From 01c68bc2a4bed263dd5ff298825e1dc25bcc2fe3 Mon Sep 17 00:00:00 2001 From: Denis Ledoux Date: Wed, 14 Sep 2016 12:44:54 +0200 Subject: [PATCH] [FIX] website_sale: fix variants availability on website product page This is an oversight during the conversion to the new API in the revision 788c1334e2cbe26fa26d4c6d4974dc413dbff608 In the above revision, ``` visible_attrs = set(l.attribute_id.id for l in product.attribute_line_ids if len(l.value_ids) > 1) ``` has been converted to ``` visible_attrs_ids = product.mapped('attribute_line_ids.attribute_id').filtered(lambda attr: len(attr.value_ids) > 1).ids ``` which leads to a change of behavior: Before the conversion, the filter is applied on the attribute line `value_ids` field: `if len(l.value_ids) > 1`, `l` being one item of `attribute_line_ids` After the converison, the filter is applied on the attribute line `attribute_id.value_ids` field `filtered(lambda attr: len(attr.value_ids) > 1)`, `attr` being the `attribute_id` field of one item of `attribute_line_ids` Therefore breaking the availability of the product variants in the products pages of the ecommerce. e.g. Attribute color, values red, blue, white, black The product "Tshirt" is defined with as possible colors values red only. Before, the filter would not return the attribute `color` for this product, as the product has only one possible value for this attribute After, the filter would return the attribute `color`, since this attribute as more than one possible values (but, not for this product) opw-688470 --- addons/website_sale/controllers/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/website_sale/controllers/main.py b/addons/website_sale/controllers/main.py index bc367eb917b..e6124ca0291 100644 --- a/addons/website_sale/controllers/main.py +++ b/addons/website_sale/controllers/main.py @@ -110,7 +110,7 @@ class WebsiteSale(http.Controller): (variant id, [visible attribute ids], variant price, variant sale price) """ # product attributes with at least two choices - visible_attrs_ids = product.mapped('attribute_line_ids.attribute_id').filtered(lambda attr: len(attr.value_ids) > 1).ids + visible_attrs_ids = product.attribute_line_ids.filtered(lambda l: len(l.value_ids) > 1).mapped('attribute_id').ids to_currency = request.website.get_current_pricelist().currency_id attribute_value_ids = [] for variant in product.product_variant_ids: