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"]