Skip to content

Commit

Permalink
Refactor create method to support multiple record creation
Browse files Browse the repository at this point in the history
Replaced `@api.model` with `@api.model_create_multi` to enable batch creation of records. Updated logic to handle a list of value dictionaries (`vals_list`) instead of a single `vals` dictionary. This improves performance and aligns with best practices for handling record creation in Odoo.
  • Loading branch information
dhongu committed Jan 26, 2025
1 parent eb616f6 commit d324030
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions deltatech_dc/models/deltatech_dc.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ def _compute_display_name(self):
for dc in self:
dc.display_name = dc.product_id + " (" + dc.name + "/" + dc.date + ")"

@api.model
def create(self, vals):
if "company_id" in vals:
self = self.with_company(vals["company_id"])
if vals.get("name", _("New")) == _("New"):
vals["name"] = self.env["ir.sequence"].next_by_code("declaration.conformity") or _("New")

result = super().create(vals)
return result
@api.model_create_multi
def create(self, vals_list):
for vals in vals_list:
if "company_id" in vals:
self = self.with_company(vals["company_id"])
if vals.get("name", _("New")) == _("New"):
vals["name"] = self.env["ir.sequence"].next_by_code("declaration.conformity") or _("New")

return super().create(vals_list)

0 comments on commit d324030

Please sign in to comment.