From 07517d79fa9f256e534caf4133b7ff9537576c07 Mon Sep 17 00:00:00 2001 From: Victor Feyens Date: Fri, 26 May 2023 13:24:50 +0200 Subject: [PATCH] [CLN] website_sale: split product_attribute.py Part-of: odoo/odoo#121986 --- addons/website_sale/models/__init__.py | 1 + .../website_sale/models/product_attribute.py | 27 +++---------------- .../models/product_template_attribute_line.py | 25 +++++++++++++++++ 3 files changed, 29 insertions(+), 24 deletions(-) create mode 100644 addons/website_sale/models/product_template_attribute_line.py diff --git a/addons/website_sale/models/__init__.py b/addons/website_sale/models/__init__.py index 44a62201a14..d25e9469764 100644 --- a/addons/website_sale/models/__init__.py +++ b/addons/website_sale/models/__init__.py @@ -15,6 +15,7 @@ from . import product_public_category from . import product_ribbon from . import product_tag from . import product_template +from . import product_template_attribute_line from . import product_template_attribute_value from . import res_company from . import res_config_settings diff --git a/addons/website_sale/models/product_attribute.py b/addons/website_sale/models/product_attribute.py index 805d5cfa9c3..eb502e18b2a 100644 --- a/addons/website_sale/models/product_attribute.py +++ b/addons/website_sale/models/product_attribute.py @@ -1,32 +1,11 @@ -# -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. -from collections import OrderedDict - from odoo import models, fields class ProductAttribute(models.Model): _inherit = 'product.attribute' - visibility = fields.Selection([('visible', 'Visible'), ('hidden', 'Hidden')], default='visible') - - -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 + visibility = fields.Selection( + selection=[('visible', "Visible"), ('hidden', "Hidden")], + default='visible') diff --git a/addons/website_sale/models/product_template_attribute_line.py b/addons/website_sale/models/product_template_attribute_line.py new file mode 100644 index 00000000000..f2e6a9c17d3 --- /dev/null +++ b/addons/website_sale/models/product_template_attribute_line.py @@ -0,0 +1,25 @@ +# 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