From e51537a430bb0710f69779a7f2a479b43e88945e Mon Sep 17 00:00:00 2001 From: Victor Feyens Date: Fri, 4 Feb 2022 14:14:31 +0000 Subject: [PATCH] [IMP] product: reduce forced cache invalidation & flushes write call on product.template.attribute.line with an active value specified will trigger cache invalidation & flush even if no record is specified in the call. _create_variant_ids is called on multiple places, including the unlink of product.template.attribute.line records. In this flow, self might be an empty recordset, and there is no need to trigger early flushes and cache invalidation if self is empty. Part-of: odoo/odoo#84055 --- addons/product/models/product_attribute.py | 2 +- addons/product/models/product_template.py | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/addons/product/models/product_attribute.py b/addons/product/models/product_attribute.py index b4f01744140..fc346679516 100644 --- a/addons/product/models/product_attribute.py +++ b/addons/product/models/product_attribute.py @@ -314,7 +314,7 @@ class ProductTemplateAttributeLine(models.Model): # We catch all kind of exceptions to be sure that the operation # doesn't fail. ptal_to_archive += ptal - ptal_to_archive.write({'active': False}) + ptal_to_archive.action_archive() # only calls write if there are records # For archived lines `_update_product_template_attribute_values` is # implicitly called during the `write` above, but for products that used # unlinked lines `_create_variant_ids` has to be called manually. diff --git a/addons/product/models/product_template.py b/addons/product/models/product_template.py index 946800ced90..8b51d5b8025 100644 --- a/addons/product/models/product_template.py +++ b/addons/product/models/product_template.py @@ -575,6 +575,9 @@ class ProductTemplate(models.Model): return prices def _create_variant_ids(self): + if not self: + return + self.flush() Product = self.env["product.product"]