[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
This commit is contained in:
@@ -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 = [
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user