From 98e7f5f710ff89266c17263f3dcdf1e5de6639a3 Mon Sep 17 00:00:00 2001 From: Yannick Tivisse Date: Fri, 27 Jan 2017 15:18:14 +0100 Subject: [PATCH] [FIX] sale_coupon: Compute correclty the reward product qty if several lines Use case ======== If apply base on a product, it takes only the first line of this product ! Eg: 1 free if 3 buy, - add 2 line of 2 will not work, - add 1 line of 1 (eg: discounted, descr, ...) and one ligne with 10... will be ignored --- models/sale_order.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/models/sale_order.py b/models/sale_order.py index 9961fe6f8f5..159390375bb 100644 --- a/models/sale_order.py +++ b/models/sale_order.py @@ -78,12 +78,11 @@ class SaleOrder(models.Model): order_lines = (self.order_line - self._get_reward_lines()).filtered(lambda x: x.product_id in program.rule_product_ids) max_product_qty = sum(order_lines.mapped('product_uom_qty')) or 1 - line = self.order_line.filtered(lambda line: line.product_id == program.reward_product_id)[0] # Remove needed quantity from reward quantity if same reward and rule product if program.reward_product_id in program.rule_product_ids: - reward_product_qty = line.product_uom_qty // (program.rule_min_quantity + program.reward_product_quantity) + reward_product_qty = max_product_qty // (program.rule_min_quantity + program.reward_product_quantity) else: - reward_product_qty = line.product_uom_qty + reward_product_qty = max_product_qty reward_qty = min(int(int(max_product_qty / program.rule_min_quantity) * program.reward_product_quantity), reward_product_qty)