From c18a7eb82ae1a4a7cfd05c6e70bbf8c81e409ca9 Mon Sep 17 00:00:00 2001 From: Olivier Dony Date: Fri, 30 Jan 2015 19:45:12 +0100 Subject: [PATCH] [FIX] website_sale: visible attributes wrongly computed for some variants On one hand, when a product attribute is shared by several products, some may use different subsets of its possible values. On the other hand, when less than 2 values are enabled for a given attribute on a product, no choice is displayed for that attribute on the shop page, as there is none to be made. The way those "visible attributes" were computed in get_attribute_values() was wrong: when counting the number of values it used the whole range of possible values for this attribute (cross-product), not just those enabled for that product. This lead to inconsistencies vs the website_sale.variants template, and products using a single value out of a larger range of values were constantly marked as "Not available" in the shop. --- addons/website_sale/controllers/main.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/addons/website_sale/controllers/main.py b/addons/website_sale/controllers/main.py index 9bed2b0f2b9..bf777b65717 100644 --- a/addons/website_sale/controllers/main.py +++ b/addons/website_sale/controllers/main.py @@ -122,14 +122,17 @@ class website_sale(http.Controller): cr, uid, context, pool = request.cr, request.uid, request.context, request.registry currency_obj = pool['res.currency'] attribute_value_ids = [] + visible_attrs = set(l.attribute_id.id + for l in product.attribute_line_ids + if len(l.value_ids) > 1) if request.website.pricelist_id.id != context['pricelist']: website_currency_id = request.website.currency_id.id currency_id = self.get_pricelist().currency_id.id for p in product.product_variant_ids: price = currency_obj.compute(cr, uid, website_currency_id, currency_id, p.lst_price) - attribute_value_ids.append([p.id, [v.id for v in p.attribute_value_ids if len(v.attribute_id.value_ids) > 1], p.price, price]) + attribute_value_ids.append([p.id, [v.id for v in p.attribute_value_ids if v.attribute_id.id in visible_attrs], p.price, price]) else: - attribute_value_ids = [[p.id, [v.id for v in p.attribute_value_ids if len(v.attribute_id.value_ids) > 1], p.price, p.lst_price] + attribute_value_ids = [[p.id, [v.id for v in p.attribute_value_ids if v.attribute_id.id in visible_attrs], p.price, p.lst_price] for p in product.product_variant_ids] return attribute_value_ids