[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) <nim@odoo.com>
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user