From c40e20c496864d640d9467211862fa46868191f1 Mon Sep 17 00:00:00 2001 From: Goffin Simon Date: Thu, 8 Oct 2020 10:26:05 +0000 Subject: [PATCH] [FIX] sale: Update pricelist when discount_policy = 'with_discount' Steps to reproduce the bug: - Let's consider two pricelist PL1 and PL2 with discount_policy = 'without_discount' - Let's consider a product P - PL1 has 10% on P and PL2 has 20% discount on P - Create a quotation Q with PL1 - Add P on Q (the 10% discount is correctly applied) - Change PL1 to PL2 and click on Update pricelist Bug: The 20% discount on P was not applied. opw:2352577 closes odoo/odoo#59541 X-original-commit: 9f1280e275fd851fce17bf82c603fdc50a8ef94e Signed-off-by: Simon Goffin (sig) --- addons/sale/models/sale.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/addons/sale/models/sale.py b/addons/sale/models/sale.py index 8fb42672d1e..0836ec09673 100644 --- a/addons/sale/models/sale.py +++ b/addons/sale/models/sale.py @@ -461,7 +461,11 @@ class SaleOrder(models.Model): ) price_unit = self.env['account.tax']._fix_tax_included_price_company( line._get_display_price(product), line.product_id.taxes_id, line.tax_id, line.company_id) - lines_to_update.append((1, line.id, {'price_unit': price_unit})) + if self.pricelist_id.discount_policy == 'without_discount': + discount = max(0, (price_unit - product.price) * 100 / price_unit) + else: + discount = 0 + lines_to_update.append((1, line.id, {'price_unit': price_unit, 'discount': discount})) self.update({'order_line': lines_to_update}) self.show_update_pricelist = False self.message_post(body=_("Product prices have been recomputed according to pricelist %s ", self.pricelist_id.display_name))