[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) <etdj@odoo.com>
Signed-off-by: Victor Feyens (vfe) <vfe@odoo.com>
This commit is contained in:
Eteil Djoumatchoua (etdj)
2023-03-27 13:48:12 +02:00
committed by Eteil Djoumatchoua(etdj)
parent 3ec3bebcbf
commit 7c71bcdfec
2 changed files with 21 additions and 5 deletions
@@ -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
@@ -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