diff options
| author | Nicolas Martinelli <nim@odoo.com> | 2019-01-16 14:39:23 +0000 |
|---|---|---|
| committer | Nicolas Martinelli <nim@odoo.com> | 2019-01-16 14:48:33 +0000 |
| commit | 180ace7b1bcef74149bc85cf2e68a0b9acdcbc09 (patch) | |
| tree | 8c2f359a76ad203c6b1461f393d8e2d27497bca9 | |
| parent | 302d8a526441b85120f1b4501bae3efcbe700d47 (diff) | |
[FIX] product: unwanted attribute values in name
- Create the following attributes with values:
Size: S, M, L, XL
Color: Black, White
- Create a product template with the following attribute values:
Size: S, M, L, XL
Color: Black
The `name_get` of `product.product` returns `Name (SIZE, Black)` while
it should only return `Name (SIZE)`.
When using `attribute_id.value_ids`, the list of values contains all
possible values of the attribute, not only the values which apply to the
given product. In this case, it contains 'Black' and 'White', therefore
the condition `> 1` is verified and the attribute is kept for display.
We go back to the original filtering, and add `attribute_line_ids` in
the list fields read in order to avoid prefetching.
opw-1922140
opw-1922447
closes odoo/odoo#30273
| -rw-r--r-- | addons/product/models/product.py | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/addons/product/models/product.py b/addons/product/models/product.py index 258f27d1ade..ecf48deeb33 100644 --- a/addons/product/models/product.py +++ b/addons/product/models/product.py @@ -398,7 +398,7 @@ class ProductProduct(models.Model): # Prefetch the fields used by the `name_get`, so `browse` doesn't fetch other fields # Use `load=False` to not call `name_get` for the `product_tmpl_id` - self.sudo().read(['name', 'default_code', 'product_tmpl_id', 'attribute_value_ids'], load=False) + self.sudo().read(['name', 'default_code', 'product_tmpl_id', 'attribute_value_ids', 'attribute_line_ids'], load=False) product_template_ids = self.sudo().mapped('product_tmpl_id').ids @@ -415,7 +415,7 @@ class ProductProduct(models.Model): supplier_info_by_template.setdefault(r.product_tmpl_id, []).append(r) for product in self.sudo(): # display only the attributes with multiple possible values on the template - variable_attributes = product.attribute_value_ids.filtered(lambda v: len(v.attribute_id.value_ids) > 1).mapped('attribute_id') + variable_attributes = product.attribute_line_ids.filtered(lambda l: len(l.value_ids) > 1).mapped('attribute_id') variant = product.attribute_value_ids._variant_name(variable_attributes) name = variant and "%s (%s)" % (product.name, variant) or product.name |
