[FIX] website_sale: fix variants availability on website product page

This is an oversight during the conversion to the new API
in the revision
788c1334e2

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
This commit is contained in:
Denis Ledoux
2016-09-14 12:59:15 +02:00
parent 19b4f5efe4
commit 01c68bc2a4
+1 -1
View File
@@ -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: