[FIX] website_sale: displayed discount on cart

Since 17.0 , calls to _get_combination_info on the
/shop/cart page were removed to avoid recomputing
values already stored on the cart, speeding up
the page loading.

See 824fc94bbc

Nevertheless, this highlighted the difference
in pricelist discount computation between sale
and website_sale.

In sale, the discount is computed while considering
the base price of the pricelist, whereas for
website_sale, the base price was always the sales price.

To make sure the crossed price displayed is the sales
price as before on /shop/cart, we override the default
sale behavior to force the sales price to be considered
as price before the pricelist discount.

closes odoo/odoo#151321

Signed-off-by: Victor Feyens (vfe) <vfe@odoo.com>
This commit is contained in:
Victor Feyens
2024-01-26 19:26:16 +00:00
parent d5d563909f
commit 330f427367
2 changed files with 19 additions and 4 deletions
+17 -2
View File
@@ -1,7 +1,6 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import api, models, fields, _
from odoo import _, api, fields, models
class SaleOrderLine(models.Model):
@@ -48,6 +47,22 @@ class SaleOrderLine(models.Model):
def get_description_following_lines(self):
return self.name.splitlines()[1:]
def _get_pricelist_price_before_discount(self):
"""On ecommerce orders, the base price must always be the sales price."""
self.ensure_one()
self.product_id.ensure_one()
if self.order_id.website_id:
return self.env['product.pricelist.item']._compute_price_before_discount(
product=self.product_id.with_context(**self._get_product_price_context()),
quantity=self.product_uom_qty or 1.0,
uom=self.product_uom,
date=self.order_id.date_order,
currency=self.currency_id,
)
return super()._get_pricelist_price_before_discount()
def _get_shop_warning(self, clear=True):
self.ensure_one()
warn = self.shop_warning
@@ -240,8 +240,8 @@ class TestWebsitePriceList(TransactionCase):
so.pricelist_id = promo_pricelist
with MockRequest(self.env, website=current_website, sale_order_id=so.id):
so._cart_update(product_id=product.id, line_id=sol.id, set_qty=500)
self.assertEqual(sol.price_unit, 37.0, 'Both reductions should be applied')
self.assertEqual(sol.discount, 25.0, 'Both reductions should be applied')
self.assertEqual(sol.price_unit, 100.0, 'Both reductions should be applied')
self.assertEqual(sol.discount, 72.25, 'Both reductions should be applied')
self.assertEqual(sol.price_total, 13875)
def test_pricelist_with_no_list_price(self):