From 7c71bcdfecd409e2db33216f25f63e8c6e803a2d Mon Sep 17 00:00:00 2001 From: "Eteil Djoumatchoua (etdj)" Date: Mon, 20 Feb 2023 10:18:42 +0000 Subject: [PATCH] [FIX] website_sale: show correct price of product not included in a pricelist discount Steps to reproduce: 1) website config: show strikethrough price (price comparison), show tax included price, discounts, pricelists(with advanced price rules). 2) create a pricelist with "show price and discount to customer", and any rule like 50% off any category (doesn't really matter). 3) apply the pricelist to the website Issue: Notice that some strikethrough price is applied wrongly - the crossed amount is the same as the written amount Cause: Strike is applied if base price not equal to price_reduce, which is actually calculated using taxes prior. it should not be the case for the tax-included product ( or base price should also have tax applied). opw-3140616 closes odoo/odoo#116668 X-original-commit: 58108a84946817175a07c5e8f09f7a5ba88266ee Signed-off-by: Djoumatchoua Eteil Junior (etdj) Signed-off-by: Victor Feyens (vfe) --- .../website_sale/models/product_template.py | 7 ++----- .../tests/test_website_sale_pricelist.py | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/addons/website_sale/models/product_template.py b/addons/website_sale/models/product_template.py index 7b140255622..e196dc210d9 100644 --- a/addons/website_sale/models/product_template.py +++ b/addons/website_sale/models/product_template.py @@ -185,12 +185,7 @@ class ProductTemplate(models.Model): product_taxes = template.sudo().taxes_id.filtered(lambda t: t.company_id == t.env.company) taxes = fiscal_position.map_tax(product_taxes) - - price_reduce = self.env['account.tax']._fix_tax_included_price_company( - price_reduce, product_taxes, taxes, self.env.company) - tax_display = 'total_excluded' if self.env.company.show_line_subtotals_tax_selection == 'tax_excluded' else 'total_included' - price_reduce = taxes.compute_all(price_reduce, currency, 1, template, partner_sudo)[tax_display] template_price_vals = { 'price_reduce': price_reduce @@ -229,6 +224,8 @@ class ProductTemplate(models.Model): fields.Datetime.now(), round=False ) + template_price_vals['price_reduce'] = self.env['account.tax']._fix_tax_included_price_company(template_price_vals['price_reduce'], product_taxes, taxes, self.env.company) + template_price_vals['price_reduce'] = taxes.compute_all(template_price_vals['price_reduce'], pricelist.currency_id, 1, template, partner_sudo)[tax_display] res[template.id] = template_price_vals diff --git a/addons/website_sale/tests/test_website_sale_pricelist.py b/addons/website_sale/tests/test_website_sale_pricelist.py index 7cb12033b69..9a95da7e483 100644 --- a/addons/website_sale/tests/test_website_sale_pricelist.py +++ b/addons/website_sale/tests/test_website_sale_pricelist.py @@ -277,6 +277,25 @@ class TestWebsitePriceList(TransactionCase): self.assertEqual(sol.discount, 0, 'Pricelist price should be applied') self.assertEqual(sol.price_total, 60.0) + def test_get_right_discount(self): + """ Test that `_get_sales_prices` from `product_template` + returns a dict with just `price_reduce` (no discount) as key + when the product is tax included. + """ + tax = self.env['account.tax'].create({ + 'name': "Tax 10", + 'amount': 10, + }) + + product = self.env['product.template'].create({ + 'name': 'Event Product', + 'list_price': 10.0, + 'taxes_id': tax, + }) + + prices = product._get_sales_prices(self.list_christmas) + self.assertFalse('base_price' in prices[product.id]) + def simulate_frontend_context(self, website_id=1): # Mock this method will be enough to simulate frontend context in most methods