Skip to content

[16.0][IMP] multicreate warning #1453

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: 16.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions hr_contract_employee_calendar_planning/models/contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,18 @@ def write(self, vals):
vals.pop("resource_calendar_id")
return super().write(vals)

@api.model
def create(self, vals):
@api.model_create_multi
def create(self, vals_list):
# the create method of contracts syncs contract calendars with employee calendars
# in order to not overwrite the employee calendar
# we set the contract calendar to match the employee calendar
employee_contract = (
self.env["hr.employee"]
.browse([vals.get("employee_id")])
.resource_calendar_id
)
if employee_contract:
vals.update({"resource_calendar_id": employee_contract.id})
contracts = super(HrContract, self).create(vals)
for vals in vals_list:
employee_id = vals.get("employee_id")
if employee_id:
employee_contract = (
self.env["hr.employee"].browse(employee_id).resource_calendar_id
)
if employee_contract:
vals.update({"resource_calendar_id": employee_contract.id})
contracts = super().create(vals_list)
return contracts
11 changes: 6 additions & 5 deletions hr_contract_reference/models/hr_contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ class HrContract(models.Model):
"Contract Reference", required=False, readonly=True, copy=False, default="/"
)

@api.model
def create(self, vals):
if vals.get("name", "/") == "/":
vals["name"] = self.env["ir.sequence"].next_by_code("contract.ref")
return super(HrContract, self).create(vals)
@api.model_create_multi
def create(self, vals_list):
for vals in vals_list:
if vals.get("name", "/") == "/":
vals["name"] = self.env["ir.sequence"].next_by_code("contract.ref")
return super().create(vals_list)
4 changes: 2 additions & 2 deletions hr_employee_id/models/hr_employee.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ def _generate_identification_id(self):
_("Unable to generate unique Employee ID in %d steps.") % (steps,)
)

@api.model
@api.model_create_multi
def create(self, vals_list):
records = super(HrEmployee, self).create(vals_list)
records = super().create(vals_list)

for record in records:
if not record.identification_id:
Expand Down
13 changes: 7 additions & 6 deletions hr_job_category/models/hr.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,13 @@ def _tag_employees(self, employee_id=None, job_id=None):
)
employee.write({"category_ids": [(4, tag.id)]})

@api.model
def create(self, vals):
res = super().create(vals)
if "job_id" in vals:
res._tag_employees(vals.get("job_id"))
return res
@api.model_create_multi
def create(self, vals_list):
records = super().create(vals_list)
for record, vals in zip(records, vals_list):
if "job_id" in vals:
record._tag_employees(vals.get("job_id"))
return records

def write(self, vals):
prev_data = self.read(["job_id"])
Expand Down