From d3240302d0a2d2b7de63d7aa5232dee83055346f Mon Sep 17 00:00:00 2001 From: Dorin Hongu Date: Sun, 26 Jan 2025 13:09:25 +0200 Subject: [PATCH] Refactor create method to support multiple record creation 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. --- deltatech_dc/models/deltatech_dc.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/deltatech_dc/models/deltatech_dc.py b/deltatech_dc/models/deltatech_dc.py index 54f957e509..2a6dfaf2e3 100644 --- a/deltatech_dc/models/deltatech_dc.py +++ b/deltatech_dc/models/deltatech_dc.py @@ -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)