From 2bb9e779d11614b2ba9f2f598d5110bc50b27fc1 Mon Sep 17 00:00:00 2001 From: "Andrea Grazioso (agr-odoo)" Date: Mon, 18 May 2020 13:16:30 +0000 Subject: [PATCH] [FW][FIX] sale_coupon: free product quantity in promotion Create a promotion program with conditions: - Minimum purchase in currency (ex 100$ tax excluded) - Auto apply - On current order - Unlimited use And reward: - Free product - 1 Quantity Go to website shop. Fill an order with amount above the minimum required by the program. The promo will apply and add the free product. Increasing the order amount will eventually make the free product quantity increase, eventually overcoming the reward product quantity. Fixing by calculating the reward quantity using both minimum quantity and minimum amount and using as cap the to reward product quantity currently in cart opw-2246138 closes odoo/odoo#51680 X-original-commit: 02331a34cf66117b27cfa1e96078b4721cbd1e70 Related: odoo/enterprise#10722 Signed-off-by: Nicolas Martinelli (nim) --- addons/sale_coupon/models/sale_order.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/addons/sale_coupon/models/sale_order.py b/addons/sale_coupon/models/sale_order.py index 44c18a36eaf..bca35bd8879 100644 --- a/addons/sale_coupon/models/sale_order.py +++ b/addons/sale_coupon/models/sale_order.py @@ -86,6 +86,11 @@ class SaleOrder(models.Model): 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 + # do not give more free reward than products + reward_product_qty = min(reward_product_qty, self.order_line.filtered(lambda x: x.product_id == program.reward_product_id).product_uom_qty) + if program.rule_minimum_amount: + order_total = sum(line.price_total for line in order_lines.filtered(lambda x: x.product_id != program.reward_product_id)) + reward_product_qty = min(reward_product_qty, order_total // program.rule_minimum_amount) else: reward_product_qty = min(max_product_qty, self.order_line.filtered(lambda x: x.product_id == program.reward_product_id).product_uom_qty)