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