From eb3257ef21aff01e9b2b745fb5281f6edf0f9234 Mon Sep 17 00:00:00 2001 From: Jeanphy Date: Sat, 16 Nov 2019 03:33:03 +0000 Subject: [PATCH] [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) --- addons/sale_coupon/models/sale_order.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/addons/sale_coupon/models/sale_order.py b/addons/sale_coupon/models/sale_order.py index f6b953cdaef..a9f0bab4edb 100644 --- a/addons/sale_coupon/models/sale_order.py +++ b/addons/sale_coupon/models/sale_order.py @@ -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)