From 330f42736748481f1bce9caa6e8b0e35bb0627d7 Mon Sep 17 00:00:00 2001 From: Victor Feyens Date: Thu, 11 Jan 2024 16:39:13 +0100 Subject: [PATCH] [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 824fc94bbcc6ea63b5416a2be59b860ef65714eb 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) --- addons/website_sale/models/sale_order_line.py | 19 +++++++++++++++++-- .../tests/test_website_sale_pricelist.py | 4 ++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/addons/website_sale/models/sale_order_line.py b/addons/website_sale/models/sale_order_line.py index 558d74fbd23..ff6db4e2521 100644 --- a/addons/website_sale/models/sale_order_line.py +++ b/addons/website_sale/models/sale_order_line.py @@ -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 diff --git a/addons/website_sale/tests/test_website_sale_pricelist.py b/addons/website_sale/tests/test_website_sale_pricelist.py index d97bf0950e0..cd591a44778 100644 --- a/addons/website_sale/tests/test_website_sale_pricelist.py +++ b/addons/website_sale/tests/test_website_sale_pricelist.py @@ -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):