From 66a1c81e36355b7569f08d1e365cb65915694421 Mon Sep 17 00:00:00 2001 From: manu Date: Thu, 6 Jun 2024 12:20:00 +0200 Subject: [PATCH] [MIG] product_variant_configurator: Migration to 17.0 --- product_variant_configurator/README.rst | 2 ++ product_variant_configurator/__manifest__.py | 2 +- .../models/ir_ui_view.py | 3 +- .../models/pricelist.py | 31 ++++++++++++++----- .../models/product_attribute_value.py | 4 +-- .../models/product_category.py | 2 +- .../models/product_configurator.py | 17 +++++----- .../models/product_configurator_attribute.py | 2 +- .../models/product_product.py | 4 +-- .../models/product_template.py | 6 ++-- .../readme/CONTRIBUTORS.md | 2 ++ .../static/description/index.html | 2 ++ .../test_product_configurator_attribute.py | 2 +- .../tests/test_product_pricelist.py | 2 +- .../test_product_variant_configurator.py | 2 +- .../tests/test_product_variants.py | 2 +- .../views/inherited_product_product_views.xml | 27 +++++++--------- .../views/product_configurator_attribute.xml | 10 +++--- 18 files changed, 71 insertions(+), 51 deletions(-) diff --git a/product_variant_configurator/README.rst b/product_variant_configurator/README.rst index 0918a7fcb..47a08237f 100644 --- a/product_variant_configurator/README.rst +++ b/product_variant_configurator/README.rst @@ -127,6 +127,8 @@ Contributors - Simone Versienti - Adria Gil Sorribes - Héctor Villarreal Ortega +- Manuel Regidor +- Valentín Vinagre Maintainers ----------- diff --git a/product_variant_configurator/__manifest__.py b/product_variant_configurator/__manifest__.py index 736d1ee02..21951be90 100644 --- a/product_variant_configurator/__manifest__.py +++ b/product_variant_configurator/__manifest__.py @@ -7,7 +7,7 @@ { "name": "Product Variant Configurator", "summary": "Provides an abstract model for product variant configuration.", - "version": "16.0.1.0.5", + "version": "17.0.1.0.0", "category": "Product Variant", "development_status": "Production/Stable", "license": "AGPL-3", diff --git a/product_variant_configurator/models/ir_ui_view.py b/product_variant_configurator/models/ir_ui_view.py index 5651f2d43..848b24ac3 100644 --- a/product_variant_configurator/models/ir_ui_view.py +++ b/product_variant_configurator/models/ir_ui_view.py @@ -12,7 +12,8 @@ def _postprocess_tag_groupby(self, node, name_manager, node_info): field of a many2one model, and that model also has the same field name. In this example, the stock.valuation.layer.tree view contains a groupby product_id, and the product.product model already has a product_id field, - relating to the same model. Without this code we would reach a recursion error.""" + relating to the same model. Without this code we would reach a recursion + error.""" name = node.get("name") if name_manager.model._name == "product.product" and name == "product_id": return diff --git a/product_variant_configurator/models/pricelist.py b/product_variant_configurator/models/pricelist.py index bc65c74ab..809267977 100644 --- a/product_variant_configurator/models/pricelist.py +++ b/product_variant_configurator/models/pricelist.py @@ -10,16 +10,28 @@ class ProductPricelist(models.Model): _inherit = "product.pricelist" - def _compute_price_rule(self, products, qty, uom=None, date=False, **kwargs): + def _compute_price_rule( + self, + products, + quantity, + currency=None, + uom=None, + date=False, + compute_price=True, + **kwargs, + ): """Overwrite for covering the case where templates are passed and a different uom is used.""" if products[0]._name != "product.template": # Standard use case - Nothing to do - return super(ProductPricelist, self)._compute_price_rule( + return super()._compute_price_rule( products, - qty, - date=date, - uom=uom, + quantity, + currency, + uom, + date, + compute_price, + **kwargs, ) # Isolate object pricelist_obj = self @@ -31,9 +43,12 @@ def _compute_price_rule(self, products, qty, uom=None, date=False, **kwargs): return super(ProductPricelist, pricelist_obj)._compute_price_rule( products, - qty, - date=date, - uom=False, + quantity, + currency, + uom, + date, + compute_price, + **kwargs, ) def template_price_get(self, prod_id, qty, partner=None): diff --git a/product_variant_configurator/models/product_attribute_value.py b/product_variant_configurator/models/product_attribute_value.py index 0e1602355..9416e819b 100644 --- a/product_variant_configurator/models/product_attribute_value.py +++ b/product_variant_configurator/models/product_attribute_value.py @@ -13,14 +13,14 @@ def create(self, vals_list): This happens when quick-creating values from the product configurator. """ - attr_values = super(ProductAttributeValue, self).create(vals_list) + attr_values = super().create(vals_list) if "template_for_attribute_value" in self.env.context: template = self.env["product.template"].browse( self.env.context["template_for_attribute_value"] ) for attr in attr_values: line = template.attribute_line_ids.filtered( - lambda x: x.attribute_id == attr.attribute_id + lambda x, attr=attr: x.attribute_id == attr.attribute_id ) line.value_ids = [(4, attr.id)] return attr_values diff --git a/product_variant_configurator/models/product_category.py b/product_variant_configurator/models/product_category.py index 49be2980a..2d7171344 100644 --- a/product_variant_configurator/models/product_category.py +++ b/product_variant_configurator/models/product_category.py @@ -30,7 +30,7 @@ def onchange_no_create_variants(self): } def write(self, values): - res = super(ProductCategory, self).write(values) + res = super().write(values) if "no_create_variants" in values and not values.get("no_create_variants"): self.env["product.template"].search( [("categ_id", "=", self.id), ("no_create_variants", "=", "empty")] diff --git a/product_variant_configurator/models/product_configurator.py b/product_variant_configurator/models/product_configurator.py index cf9e46681..e726d3635 100644 --- a/product_variant_configurator/models/product_configurator.py +++ b/product_variant_configurator/models/product_configurator.py @@ -200,7 +200,7 @@ def _order_attributes(self, template, product_attribute_values): res2 = [] for val in res: value = product_attribute_values.filtered( - lambda x: x.attribute_id.id == val["attribute_id"] + lambda x, val=val: x.attribute_id.id == val["attribute_id"] ) if value: val["value_id"] = value @@ -252,7 +252,7 @@ def create(self, vals_list): def unlink(self): """Mimic `ondelete="cascade"`.""" attributes = self.mapped("product_attribute_ids") - result = super(ProductConfigurator, self).unlink() + result = super().unlink() if result: attributes.unlink() return result @@ -281,14 +281,15 @@ def create_variant_if_needed(self): product_attribute = product_attribute_value.attribute_id existing_attribute_line = ( self.product_tmpl_id.attribute_line_ids.filtered( # noqa - lambda l: l.attribute_id == product_attribute + lambda line, + product_attribute=product_attribute: line.attribute_id + == product_attribute ) ) - product_template_attribute_values |= ( - existing_attribute_line.product_template_value_ids.filtered( # noqa - lambda v: v.product_attribute_value_id - == product_attribute_value - ) + product_template_attribute_values |= existing_attribute_line.product_template_value_ids.filtered( # noqa + lambda v, + prod_attr_val=product_attribute_value: v.product_attribute_value_id + == prod_attr_val ) product = product_obj.create( { diff --git a/product_variant_configurator/models/product_configurator_attribute.py b/product_variant_configurator/models/product_configurator_attribute.py index fc7dbff18..bba7eb2d0 100644 --- a/product_variant_configurator/models/product_configurator_attribute.py +++ b/product_variant_configurator/models/product_configurator_attribute.py @@ -44,7 +44,7 @@ def _compute_possible_value_ids(self): for record in self: # This should be unique due to the new constraint added attribute = record.product_tmpl_id.attribute_line_ids.filtered( - lambda x: x.attribute_id == record.attribute_id + lambda x, record=record: x.attribute_id == record.attribute_id ) record.possible_value_ids = attribute.value_ids.sorted() diff --git a/product_variant_configurator/models/product_product.py b/product_variant_configurator/models/product_product.py index ef5c882a4..dac1f6f2c 100644 --- a/product_variant_configurator/models/product_product.py +++ b/product_variant_configurator/models/product_product.py @@ -16,7 +16,7 @@ def _get_product_attributes_values_dict(self): res = self.product_tmpl_id._get_product_attributes_dict() for val in res: value = self.product_template_attribute_value_ids.filtered( - lambda x: x.attribute_id.id == val["attribute_id"] + lambda x, val=val: x.attribute_id.id == val["attribute_id"] ) val["value_id"] = value.product_attribute_value_id.id return res @@ -171,4 +171,4 @@ def create(self, vals_list): ) vals.pop("product_attribute_ids") vals["product_template_attribute_value_ids"] = [(4, x) for x in ptav] - return super(ProductProduct, self).create(vals_list) + return super().create(vals_list) diff --git a/product_variant_configurator/models/product_template.py b/product_variant_configurator/models/product_template.py index e0d091cd9..fc09333ea 100644 --- a/product_variant_configurator/models/product_template.py +++ b/product_variant_configurator/models/product_template.py @@ -50,10 +50,10 @@ def create(self, vals_list): for vals in vals_list: # Needed because ORM removes this value from the dictionary vals["name"] = self.env.context["product_name"] - return super(ProductTemplate, self).create(vals_list) + return super().create(vals_list) def write(self, values): - res = super(ProductTemplate, self).write(values) + res = super().write(values) if "no_create_variants" in values: self._create_variant_ids() return res @@ -86,7 +86,7 @@ def name_search(self, name="", args=None, operator="ilike", limit=100): name=name, args=args, operator=operator, limit=limit ) # Make the other search - temp += super(ProductTemplate, self).name_search( + temp += super().name_search( name=name, args=args, operator=operator, limit=limit ) # Merge both results diff --git a/product_variant_configurator/readme/CONTRIBUTORS.md b/product_variant_configurator/readme/CONTRIBUTORS.md index 6c2d1a226..a235fcac7 100644 --- a/product_variant_configurator/readme/CONTRIBUTORS.md +++ b/product_variant_configurator/readme/CONTRIBUTORS.md @@ -9,3 +9,5 @@ - Simone Versienti \<\> - Adria Gil Sorribes \<\> - Héctor Villarreal Ortega \<\> +- Manuel Regidor \<\> +- Valentín Vinagre \<\> diff --git a/product_variant_configurator/static/description/index.html b/product_variant_configurator/static/description/index.html index 1039bff0c..c6d078256 100644 --- a/product_variant_configurator/static/description/index.html +++ b/product_variant_configurator/static/description/index.html @@ -468,6 +468,8 @@

Contributors

  • Simone Versienti <s.versienti@apuliasoftware.it>
  • Adria Gil Sorribes <adria.gil@forgeflow.com>
  • Héctor Villarreal Ortega <hector.villarreal@forgeflow.com>
  • +
  • Manuel Regidor <manuel.regidor@sygel.es>
  • +
  • Valentín Vinagre <valentin.vinagre@sygel.es>
  • diff --git a/product_variant_configurator/tests/test_product_configurator_attribute.py b/product_variant_configurator/tests/test_product_configurator_attribute.py index 1460ecd61..ea5b6ce7a 100644 --- a/product_variant_configurator/tests/test_product_configurator_attribute.py +++ b/product_variant_configurator/tests/test_product_configurator_attribute.py @@ -8,7 +8,7 @@ class TestProductConfiguratorAttribute(TransactionCase): @classmethod def setUpClass(cls): - super(TestProductConfiguratorAttribute, cls).setUpClass() + super().setUpClass() # ENVIRONMENTS cls.product_attribute = cls.env["product.attribute"] cls.product_attribute_value = cls.env["product.attribute.value"] diff --git a/product_variant_configurator/tests/test_product_pricelist.py b/product_variant_configurator/tests/test_product_pricelist.py index a42161139..8cfb4e10f 100644 --- a/product_variant_configurator/tests/test_product_pricelist.py +++ b/product_variant_configurator/tests/test_product_pricelist.py @@ -8,7 +8,7 @@ class TestProductPriceList(TransactionCase): @classmethod def setUpClass(cls): - super(TestProductPriceList, cls).setUpClass() + super().setUpClass() # ENVIRONMENTS cls.product_template = cls.env["product.template"].with_context( diff --git a/product_variant_configurator/tests/test_product_variant_configurator.py b/product_variant_configurator/tests/test_product_variant_configurator.py index 8c7df2ab8..ed8f0576a 100644 --- a/product_variant_configurator/tests/test_product_variant_configurator.py +++ b/product_variant_configurator/tests/test_product_variant_configurator.py @@ -10,7 +10,7 @@ class TestProductVariantConfigurator(TransactionCase): @classmethod def setUpClass(cls): - super(TestProductVariantConfigurator, cls).setUpClass() + super().setUpClass() # ENVIRONMENTS cls.product_attribute = cls.env["product.attribute"] diff --git a/product_variant_configurator/tests/test_product_variants.py b/product_variant_configurator/tests/test_product_variants.py index 0e560cabb..be46d32c0 100644 --- a/product_variant_configurator/tests/test_product_variants.py +++ b/product_variant_configurator/tests/test_product_variants.py @@ -6,7 +6,7 @@ class TestProductVariant(TransactionCase): def setUp(self): - super(TestProductVariant, self).setUp() + super().setUp() self.tmpl_model = self.env["product.template"].with_context( check_variant_creation=True ) diff --git a/product_variant_configurator/views/inherited_product_product_views.xml b/product_variant_configurator/views/inherited_product_product_views.xml index 502714ff7..743458c10 100644 --- a/product_variant_configurator/views/inherited_product_product_views.xml +++ b/product_variant_configurator/views/inherited_product_product_views.xml @@ -6,20 +6,17 @@ - {'invisible': ['|', ('id', '!=', False), ('product_tmpl_id', '!=', False)], 'readonly': [('product_tmpl_id', '!=', False)]} + id or product_tmpl_id + product_tmpl_id Product Template 0 - 0 - {'readonly': [('id', '!=', False)], 'required': [('id', '!=', False)]} + id + id -

    +

    Select a template for a variant. Keep empty for a new full product.

    @@ -39,26 +36,26 @@ name="product_attribute_ids" nolabel="1" colspan="2" - attrs="{'invisible': ['|', ('id','!=',False), '|', ('product_tmpl_id','=',False), ('product_attribute_ids', '=', [])]}" + invisible="id or not product_tmpl_id or not product_attribute_ids" context="{'default_product_template_id': product_tmpl_id, 'default_owner_model': 'product.product', 'show_price_extra': True, 'show_attribute': False}" > - - + + - +
    @@ -67,7 +64,7 @@ for="product_id" string="This product already exists." style="color: red;" - attrs="{'invisible': [('product_id', '=', False)]}" + invisible="not product_id" /> diff --git a/product_variant_configurator/views/product_configurator_attribute.xml b/product_variant_configurator/views/product_configurator_attribute.xml index 80ddd0ebf..2ab0e2749 100644 --- a/product_variant_configurator/views/product_configurator_attribute.xml +++ b/product_variant_configurator/views/product_configurator_attribute.xml @@ -4,22 +4,22 @@ product.configurator.attribute - - + + - +