[FIX] sale_coupon: correct qty for the reward product

Before this commit, a promotion program such as 'Buy 10, get 2 fore free'
would have only added a single product in the reward. This commit fixes
this problem by ensuring that the quantity for the reward product is computed
as the number of times the program is applicable multiplied by the configured
reward quantity, instead of just counting the number of times the program is
applicable.

closes odoo/odoo#42768

X-original-commit: 4251d44c2e635e0a78d2320cf020777ad5c55722
Signed-off-by: Martin Trigaux (mat) <mat@odoo.com>
This commit is contained in:
Jeanphy
2020-01-06 13:55:30 +00:00
committed by Martin Trigaux
parent 22f736ca38
commit eb3257ef21
+4 -1
View File
@@ -83,7 +83,10 @@ class SaleOrder(models.Model):
max_product_qty = sum(order_lines.mapped('product_uom_qty')) or 1
# Remove needed quantity from reward quantity if same reward and rule product
if program._is_valid_product(program.reward_product_id):
reward_product_qty = max_product_qty // (program.rule_min_quantity + program.reward_product_quantity)
# number of times the program should be applied
program_in_order = max_product_qty // (program.rule_min_quantity + program.reward_product_quantity)
# multipled by the reward qty
reward_product_qty = program.reward_product_quantity * program_in_order
else:
reward_product_qty = min(max_product_qty, self.order_line.filtered(lambda x: x.product_id == program.reward_product_id).product_uom_qty)