diff --git a/addons/product/models/product_template.py b/addons/product/models/product_template.py index 182997ce166..a04bec14625 100644 --- a/addons/product/models/product_template.py +++ b/addons/product/models/product_template.py @@ -406,7 +406,7 @@ class ProductTemplate(models.Model): ] # get the value (id) sets of existing variants - existing_variants = {frozenset(variant.attribute_value_ids.ids) for variant in tmpl_id.product_variant_ids} + existing_variants = {frozenset(variant.attribute_value_ids.filtered(lambda r: r.attribute_id.create_variant).ids) for variant in tmpl_id.product_variant_ids} # -> for each value set, create a recordset of values to create a # variant for if the value set isn't already a variant to_create_variants = [ diff --git a/addons/product/tests/test_variants.py b/addons/product/tests/test_variants.py index 1a621d689cb..7917a0d4a2b 100644 --- a/addons/product/tests/test_variants.py +++ b/addons/product/tests/test_variants.py @@ -330,3 +330,23 @@ class TestVariantsNoCreate(common.TestProductCommon): {variant.attribute_value_ids for variant in template.product_variant_ids}, {self.prod_attr1_v1, self.prod_attr1_v2}, ) + + def test_update_variant_with_nocreate(self): + """ update variants with a 'nocreate' value on variant """ + template = self.env['product.template'].create({ + 'name': 'Sofax', + 'uom_id': self.uom_unit.id, + 'uom_po_id': self.uom_unit.id, + 'attribute_line_ids': [ + (0, 0, { # one variant for this one + 'attribute_id': self.prod_att_1.id, + 'value_ids': [(4, self.prod_attr1_v1.id)], + }), + ], + }) + self.assertEqual(len(template.product_variant_ids), 1) + + for variant_id in template.product_variant_ids: + variant_id.attribute_value_ids += self.size_S + template.attribute_line_ids += template.attribute_line_ids.browse() + self.assertEqual(len(template.product_variant_ids), 1)