From 018b53bc156c5251d67b5c49abe1309a0129e7ca Mon Sep 17 00:00:00 2001 From: Nicolas Martinelli Date: Fri, 4 Mar 2016 15:40:38 +0100 Subject: [PATCH] [FIX] product: do not add same attribute on product Adding an attribute with only one value does not recreate the product, but write this attribute on every product instead. However, the current filter is not correct: it checks if the given attribute value is not already in the list of attribute values of the product. The appropriate check is to verify that the attribute itself is not already in the list of attributes of the product. Indeed, there is a constraint to prevent the same attribute to have two different values on the same product. BTW, it's a new api function (`mapped`) inside an old api module. Not the cleanest way to do it, but simpler to write. opw-671114 --- addons/product/product.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/product/product.py b/addons/product/product.py index c592b9a23d8..e88639db877 100644 --- a/addons/product/product.py +++ b/addons/product/product.py @@ -643,7 +643,7 @@ class product_template(osv.osv): for variant_id in variant_alone: product_ids = [] for product_id in tmpl_id.product_variant_ids: - if variant_id.id not in map(int, product_id.attribute_value_ids): + if not variant_id.attribute_id <= product_id.mapped('attribute_value_ids').mapped('attribute_id'): product_ids.append(product_id.id) product_obj.write(cr, uid, product_ids, {'attribute_value_ids': [(4, variant_id.id)]}, context=ctx)