From 60974227cf29d74c1f5d1270c47595073bbbee98 Mon Sep 17 00:00:00 2001 From: Nicolas Lempereur Date: Fri, 23 Feb 2018 17:37:46 +0100 Subject: [PATCH] [FIX] product: create_variant forward-port 5c2380e In 5c2380e9f an issue when modifying variants values was solved when an attribute on the product variant had "create_variant" unset. This commit forward-port what was lost of it in 11.0, that part was probably lost because the code was previously changed when adapting to python3. Without the change, the added test failed creating a new variant keeping the existing one. With this change, 'nocreate' value are ignored when computing new variants to create. opw-1815226 closes #23332 --- addons/product/models/product_template.py | 2 +- addons/product/tests/test_variants.py | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) 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)