From d5f855be9e49bf7c236a5bbad63ddd9a4712024a Mon Sep 17 00:00:00 2001 From: Florent de Labarre Date: Sat, 23 Oct 2021 06:33:55 +0000 Subject: [PATCH] [FIX] product: same price with different pricelist - Create a report to show price on each template --> Issue: The price is the same closes odoo/odoo#78870 Signed-off-by: Victor Feyens (vfe) --- addons/product/models/product_template.py | 1 + .../product/tests/test_product_pricelist.py | 29 +++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/addons/product/models/product_template.py b/addons/product/models/product_template.py index b47df281432..ea4c690e9b5 100644 --- a/addons/product/models/product_template.py +++ b/addons/product/models/product_template.py @@ -188,6 +188,7 @@ class ProductTemplate(models.Model): def _compute_cost_currency_id(self): self.cost_currency_id = self.env.company.currency_id.id + @api.depends_context('pricelist', 'partner', 'quantity', 'uom', 'date', 'company') def _compute_template_price(self): prices = self._compute_template_price_no_inverse() for template in self: diff --git a/addons/product/tests/test_product_pricelist.py b/addons/product/tests/test_product_pricelist.py index 657928357b1..27286be43f8 100644 --- a/addons/product/tests/test_product_pricelist.py +++ b/addons/product/tests/test_product_pricelist.py @@ -79,6 +79,10 @@ class TestProductPricelist(TransactionCase): 'name': 'Acoustic Bloc Screens', 'categ_id': self.category_5_id, }) + self.product_multi_price = self.env['product.product'].create({ + 'name': 'Multi Price', + 'categ_id': self.env.ref('product.product_category_1').id, + }) self.uom_unit_id = self.ref('uom.product_uom_unit') self.list0 = self.ref('product.list0') @@ -130,6 +134,24 @@ class TestProductPricelist(TransactionCase): 'compute_price': 'formula', 'price_discount': 50, 'base': 'list_price' + }), (0, 0, { + 'name': 'Multi Price Customer', + 'applied_on': '1_product', + 'product_tmpl_id': self.product_multi_price.product_tmpl_id.id, + 'compute_price': 'fixed', + 'fixed_price': 99, + 'base': 'list_price' + })] + }) + self.business_pricelist = self.ProductPricelist.create({ + 'name': 'Business Pricelist', + 'item_ids': [(0, 0, { + 'name': 'Multi Price Business', + 'applied_on': '1_product', + 'product_tmpl_id': self.product_multi_price.product_tmpl_id.id, + 'compute_price': 'fixed', + 'fixed_price': 50, + 'base': 'list_price' })] }) @@ -201,4 +223,11 @@ class TestProductPricelist(TransactionCase): float_compare(monitor.price, monitor.lst_price/2, precision_digits=2), 0, msg) + # Check if the price is different when we change the pricelist + product = self.product_multi_price.product_tmpl_id.with_context(pricelist=self.customer_pricelist.id, quantity=1) + msg = "Wrong price: Multi Product Price. should be 99 instead of %s" % product.price + self.assertEqual(float_compare(product.price, 99, precision_digits=2), 0) + product = self.product_multi_price.product_tmpl_id.with_context(pricelist=self.business_pricelist.id, quantity=1) + msg = "Wrong price: Multi Product Price. should be 50 instead of %s" % product.price + self.assertEqual(float_compare(product.price, 50, precision_digits=2), 0)