Files
odoo_source/addons/website_sale/models/product_attribute.py
T
Sébastien TheysandJuhil Somaiya 30d3ac79c7 [IMP] product, *: allow multiple lines for the same attribute
* = sale, website_sale, website_sale_comparison

Purpose
=======

This allows to handle use cases such as grape varieties for wine products where
multiple values need to be set for the same attribute, but they are all
informative and should not generate a choice or variants.

The general logic that existed previously is kept:
- multiple attribute lines on a product behave as an AND between them
- multiple values on a line behave as an OR between them

Example
=======

To generate 2 variants, with one possible value for each:
Line A: val 1, val 2

To generate 1 variant, with both informative values on it:
Line A: val 1
Line A: val 2

Technically
===========

- remove the constraints that prevented this use case from working since the
refactoring done in the previous commit removed the ambiguity when two
different lines have the same value
- update the product and comparison views accordingly

Extra
=====

- make the attribute category translatable and improve its list view

Final part of task-1912579

PR: #32946

Signed-off-by: Sébastien Theys (seb) <seb@odoo.com>


Co-authored-by: Juhil Somaiya <jso@odoo.com>
Co-authored-by: Sébastien Theys <seb@odoo.com>
2019-08-26 13:01:14 +00:00

27 lines
1.1 KiB
Python

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from collections import OrderedDict
from odoo import models
class ProductTemplateAttributeLine(models.Model):
_inherit = 'product.template.attribute.line'
def _prepare_single_value_for_display(self):
"""On the product page group together the attribute lines that concern
the same attribute and that have only one value each.
Indeed those are considered informative values, they do not generate
choice for the user, so they are displayed below the configurator.
The returned attributes are ordered as they appear in `self`, so based
on the order of the attribute lines.
"""
single_value_lines = self.filtered(lambda ptal: len(ptal.value_ids) == 1)
single_value_attributes = OrderedDict([(pa, self.env['product.template.attribute.line']) for pa in single_value_lines.attribute_id])
for ptal in single_value_lines:
single_value_attributes[ptal.attribute_id] |= ptal
return single_value_attributes