[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) <sig@openerp.com>
This commit is contained in:
Goffin Simon
2020-10-08 15:46:54 +00:00
parent ed22cea4a4
commit c40e20c496
+5 -1
View File
@@ -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 <b>%s<b> ", self.pricelist_id.display_name))