[IMP] sale_product_configurator: module cleanup

* correct python file name
* alphabetical ordering of imports
* demo data indentation

Part-of: odoo/odoo#85001
This commit is contained in:
Victor Feyens
2022-02-25 11:40:19 +00:00
parent 58ac6db1fe
commit c82681f1ab
4 changed files with 34 additions and 31 deletions
+1 -1
View File
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
from . import models
from . import controllers
from . import models
from . import wizard
@@ -1,25 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="1">
<record id="product_product_1_product_template" model="product.template">
<field name="name">Chair floor protection</field>
<field name="categ_id" ref="product.product_category_5"/>
<field name="list_price">12.0</field>
<field name="weight">0.01</field>
<field name="uom_id" ref="uom.product_uom_unit"/>
<field name="uom_po_id" ref="uom.product_uom_unit"/>
<field name="description_sale">Office chairs can harm your floor: protect it.</field>
<field name="image_1920" type="base64" file="sale/static/img/floor_protection-image.jpg"/>
</record>
<odoo noupdate="1">
<record id="product_product_1_product_template" model="product.template">
<field name="name">Chair floor protection</field>
<field name="categ_id" ref="product.product_category_5"/>
<field name="list_price">12.0</field>
<field name="weight">0.01</field>
<field name="uom_id" ref="uom.product_uom_unit"/>
<field name="uom_po_id" ref="uom.product_uom_unit"/>
<field name="description_sale">Office chairs can harm your floor: protect it.</field>
<field name="image_1920" type="base64" file="sale/static/img/floor_protection-image.jpg"/>
</record>
<record id="product.product_product_4_product_template" model="product.template">
<field name="optional_product_ids" eval="[(6,0,[ref('product.product_product_11_product_template')])]"/>
</record>
<record id="product.product_product_11_product_template" model="product.template">
<field name="optional_product_ids" eval="[(6,0,[ref('product_product_1_product_template')])]"/>
</record>
<record id="product.product_product_13_product_template" model="product.template">
<field name="optional_product_ids" eval="[(6,0,[ref('product.product_product_11_product_template')])]"/>
</record>
<record id="product.product_product_4_product_template" model="product.template">
<field name="optional_product_ids" eval="[(6,0,[ref('product.product_product_11_product_template')])]"/>
</record>
<record id="product.product_product_11_product_template" model="product.template">
<field name="optional_product_ids" eval="[(6,0,[ref('product_product_1_product_template')])]"/>
</record>
<record id="product.product_product_13_product_template" model="product.template">
<field name="optional_product_ids" eval="[(6,0,[ref('product.product_product_11_product_template')])]"/>
</record>
</data>
</odoo>
@@ -1,4 +1,4 @@
# -*- coding: utf-8 -*-
from . import product_template
from . import sale_order_line
from . import product
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import fields, models, api
from odoo import api, fields, models
class ProductTemplate(models.Model):
@@ -21,9 +21,11 @@ class ProductTemplate(models.Model):
- It has any attribute line with at least 2 attribute values configured
- It has at least one custom attribute value """
for product in self:
product.has_configurable_attributes = any(attribute.create_variant == 'dynamic' for attribute in product.mapped('attribute_line_ids.attribute_id')) \
or any(len(attribute_line_id.value_ids) >= 2 for attribute_line_id in product.attribute_line_ids) \
or any(attribute_value.is_custom for attribute_value in product.mapped('attribute_line_ids.value_ids'))
product.has_configurable_attributes = (
any(attribute.create_variant == 'dynamic' for attribute in product.attribute_line_ids.attribute_id)
or any(len(attribute_line_id.value_ids) >= 2 for attribute_line_id in product.attribute_line_ids)
or any(attribute_value.is_custom for attribute_value in product.attribute_line_ids.value_ids)
)
def get_single_product_variant(self):
""" Method used by the product configurator to check if the product is configurable or not.
@@ -31,12 +33,13 @@ class ProductTemplate(models.Model):
We need to open the product configurator if the product:
- is configurable (see has_configurable_attributes)
- has optional products """
self.ensure_one()
res = super(ProductTemplate, self).get_single_product_variant()
res = super().get_single_product_variant()
if res.get('product_id', False):
has_optional_products = False
for optional_product in self.product_variant_id.optional_product_ids:
if optional_product.has_dynamic_attributes() or optional_product._get_possible_variants(self.product_variant_id.product_template_attribute_value_ids):
if optional_product.has_dynamic_attributes() or optional_product._get_possible_variants(
self.product_variant_id.product_template_attribute_value_ids
):
has_optional_products = True
break
res.update({'has_optional_products': has_optional_products})