From 296eff6870a4d9037141478cf7d37ce10d4104b4 Mon Sep 17 00:00:00 2001 From: Emanuel Cino Date: Thu, 13 Apr 2023 16:27:26 +0200 Subject: [PATCH] [MIG] product_variant_sale_price: Migration to 16.0 --- .../models/product_product.py | 21 +++--- .../tests/test_product_product.py | 6 +- .../views/product_views.xml | 64 ++++++++++++------- 3 files changed, 52 insertions(+), 39 deletions(-) diff --git a/product_variant_sale_price/models/product_product.py b/product_variant_sale_price/models/product_product.py index 2e9585aec..d567af7fe 100644 --- a/product_variant_sale_price/models/product_product.py +++ b/product_variant_sale_price/models/product_product.py @@ -34,27 +34,25 @@ def _compute_lst_price(self): uom_model = self.env["uom.uom"] for product in self: price = product.fix_price or product.list_price - if "uom" in self.env.context: - price = product.uom_id._compute_price( - price, uom_model.browse(self.env.context["uom"]) - ) + if self.env.context.get("uom"): + context_uom = uom_model.browse(self.env.context["uom"]) + price = product.uom_id._compute_price(price, context_uom) product.lst_price = price def _compute_list_price(self): uom_model = self.env["uom.uom"] for product in self: price = product.fix_price or product.product_tmpl_id.list_price - if "uom" in self.env.context: - price = product.uom_id._compute_price( - price, uom_model.browse(self.env.context["uom"]) - ) + if self.env.context.get("uom"): + context_uom = uom_model.browse(self.env.context["uom"]) + price = product.uom_id._compute_price(price, context_uom) product.list_price = price def _inverse_product_lst_price(self): uom_model = self.env["uom.uom"] for product in self: vals = {} - if "uom" in self.env.context: + if self.env.context.get("uom"): vals["fix_price"] = product.uom_id._compute_price( product.lst_price, uom_model.browse(self.env.context["uom"]) ) @@ -63,9 +61,8 @@ def _inverse_product_lst_price(self): if product.product_variant_count == 1: product.product_tmpl_id.list_price = vals["fix_price"] else: - fix_prices = product.product_tmpl_id.mapped( - "product_variant_ids.fix_price" - ) + other_products = product.product_tmpl_id.product_variant_ids - product + fix_prices = other_products.mapped("fix_price") + [product.lst_price] # for consistency with price shown in the shop product.product_tmpl_id.with_context( skip_update_fix_price=True diff --git a/product_variant_sale_price/tests/test_product_product.py b/product_variant_sale_price/tests/test_product_product.py index dfd71ea7a..a71d4885e 100644 --- a/product_variant_sale_price/tests/test_product_product.py +++ b/product_variant_sale_price/tests/test_product_product.py @@ -67,11 +67,11 @@ def test_post_init_hook(self): ) # Flush the records to DB before direct SQL - self.product_blue.flush() - self.product_red.flush() + self.product_template.product_variant_ids.flush_model() + self.product_blue.product_template_attribute_value_ids.flush_model() set_sale_price_on_variant(self.cr, None, self.product_template.id) - self.product_template.product_variant_ids.invalidate_cache() + self.product_template.product_variant_ids.invalidate_recordset() self.assertEqual( self.product_template.list_price + 100.00, self.product_blue.lst_price ) diff --git a/product_variant_sale_price/views/product_views.xml b/product_variant_sale_price/views/product_views.xml index d2da65ff1..ac2ea7a3b 100644 --- a/product_variant_sale_price/views/product_views.xml +++ b/product_variant_sale_price/views/product_views.xml @@ -5,37 +5,53 @@ product.template - - {'invisible': [ - ('product_variant_count', '>', 1) - ]} - + +
+ Setting the price here will update all variants. +
+
- + product.product - + - - - + + + + - - product.product - + + + product.template.attribute.value.tree.hide.extra + product.template.attribute.value + + + + 1 + + + + + product.template.attribute.value.form.hide.extra + product.template.attribute.value + - - - + + 1 +