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):