Skip to content
Snippets Groups Projects
Unverified Commit 20e19fdf authored by Laurent Smet's avatar Laurent Smet Committed by Damien Bouvy
Browse files

[FIX] product: remove empty variant on first attribute add

Adding the attributes leave all the old variants available.

While not completely intuitive, this behaviour is not inherently
wrong. However, on the first attribute addition, it leaves a variant
with 0 attributes that can cause problems in the ecommerce. This commit
make it so that this empty variant is archived.
parent 5f1c771b
No related branches found
No related tags found
No related merge requests found
......@@ -375,6 +375,12 @@ class ProductTemplate(models.Model):
variant_matrix = itertools.product(*(line.value_ids for line in tmpl_id.attribute_line_ids if line.value_ids and line.value_ids[0].attribute_id.create_variant))
variant_matrix = map(lambda record_list: reduce(lambda x, y: x+y, record_list, self.env['product.attribute.value']), variant_matrix)
to_create_variants = filter(lambda rec_set: set(rec_set.ids) not in existing_variants, variant_matrix)
# archive dummy variant
if len(existing_variants) > 0:
for variant in tmpl_id.product_variant_ids:
if len(variant.attribute_value_ids.ids) == 0:
variant.write({'active': False})
# adding an attribute with only one value should not recreate product
# write this attribute on every product to make sure we don't lose them
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment