From a43bec5ab1db4fe8515a539838f8f75b7267c36b Mon Sep 17 00:00:00 2001 From: RabbitJon-S73 Date: Wed, 1 Feb 2023 11:28:24 +0100 Subject: [PATCH] [MIG] product_variant_sale_price: Migration to 16.0 --- product_variant_sale_price/__manifest__.py | 2 +- .../models/product_product.py | 16 +++++++--------- .../tests/test_product_product.py | 6 +++--- .../odoo/addons/product_variant_sale_price | 1 + setup/product_variant_sale_price/setup.py | 6 ++++++ 5 files changed, 18 insertions(+), 13 deletions(-) create mode 120000 setup/product_variant_sale_price/odoo/addons/product_variant_sale_price create mode 100644 setup/product_variant_sale_price/setup.py diff --git a/product_variant_sale_price/__manifest__.py b/product_variant_sale_price/__manifest__.py index de670560c..43baf374d 100644 --- a/product_variant_sale_price/__manifest__.py +++ b/product_variant_sale_price/__manifest__.py @@ -5,7 +5,7 @@ { "name": "Product Variant Sale Price", "summary": "Allows to write fixed prices in product variants", - "version": "15.0.1.0.0", + "version": "16.0.1.0.0", "category": "Product Management", "website": "https://github.com/OCA/product-variant", "author": "Tecnativa, " "Odoo Community Association (OCA)", diff --git a/product_variant_sale_price/models/product_product.py b/product_variant_sale_price/models/product_product.py index 2e9585aec..a685d3af5 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"]) ) diff --git a/product_variant_sale_price/tests/test_product_product.py b/product_variant_sale_price/tests/test_product_product.py index dfd71ea7a..30f5f5ad8 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_blue.env.flush_all() + self.product_red.env.flush_all() 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/setup/product_variant_sale_price/odoo/addons/product_variant_sale_price b/setup/product_variant_sale_price/odoo/addons/product_variant_sale_price new file mode 120000 index 000000000..0d9d066df --- /dev/null +++ b/setup/product_variant_sale_price/odoo/addons/product_variant_sale_price @@ -0,0 +1 @@ +../../../../product_variant_sale_price \ No newline at end of file diff --git a/setup/product_variant_sale_price/setup.py b/setup/product_variant_sale_price/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/product_variant_sale_price/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)