Apply promotion on any line reduced

This is what customers are expecting when promotions and price list are in
competition.

issue9406
review297941002
This commit is contained in:
Cédric Krier committed 2020-06-24 22:59:23 +02:00
1 parent 6237e2c07f
commit 0860e3c331
2 files changed
+8 -7

No files matched your search

+2
View File
@@ -1,3 +1,5 @@
* Apply promotion on any reduced line
Version 5.6.0 - 2020-05-04
* Bug fixes (see mercurial logs for details)
+6 -7
View File
@@ -236,20 +236,19 @@ class Promotion(
return True
def apply(self, sale):
new_prices = {}
applied = False
for line in sale.lines:
if line.type != 'line':
continue
if not self.is_valid_sale_line(line):
continue
context = self.get_context_formula(line)
new_prices[line] = self.get_unit_price(**context)
# Apply promotion only if all unit prices decrease
if all(l.unit_price >= p for l, p in new_prices.items()):
for line, unit_price in new_prices.items():
line.unit_price = round_price(unit_price)
new_price = self.get_unit_price(**context)
if line.unit_price >= new_price:
line.unit_price = round_price(new_price)
line.promotion = self
applied = True
if applied:
sale.lines = sale.lines # Trigger the change
def get_context_formula(self, sale_line):