From b236ca3f15494957baf96c5eaf3883fd261d959a Mon Sep 17 00:00:00 2001 From: Romain Derie Date: Mon, 27 Nov 2017 15:08:47 +0100 Subject: [PATCH] [FIX] sale_coupon: incorrect free product qty Note: The following bugs were also impacting the e-commerce. This commit fixes some bugs related to promotion program offering free product: - Create a promotion program that offers an ipad if you buy 3 of them, so the fourth is free (reduced in total) 1. Buying 4, getting a free one, removing one, free one remains - Create a quotation with 3 ipad, save and update promotions, you don't have a free one, which is 'correct' - Edit, change the qty to 4 ipad, save, update promotions, you have a free ipad (reduced from total), still correct - Edit, change the qty back to 3 ipad, update ptomotions, you still have a free ipad even if you only bought 3 of them (the way it is designed, the free ipad should only appears when you order your fourth). 2. Exponential bug: buy a lot of ipad, get a lot of free ipad then set the qty to a lower amount, you will have a lot more free ipad than you should. It can even lead to a negative amount (more free ipad than you paid ipad, but in that case you won't be able to confirm the sale). - Create a quotation with 100 ipad, you get 31 free ipad (which is incorrect, see bug 3) - Edit and change the qty back to 10 ipad and save - Update promotions, you will have 10 ipad to pay and 10 free ipad resulting in a null total. 3. Buy X ipad, get Y+Z free instead of Y (lets illustrate with 10) - Create a quotation with 10 ipad, you get 3 free ipad instead of 2 - Indeed, your first 4 ipad should give you a free one - Your next 4 ipad should give you a second one (you got 8) - The last 2 (to reach 10) are not enough to give you a third free ipad This is because free products are reward lines in the SO (is_reward_line) but not linked to an applied_coupon_ids Now, these reward lines will be considered as such and the coupon computing will return correct results This closes #1643 --- models/sale_order.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/models/sale_order.py b/models/sale_order.py index 2ad94ebbfac..9ce09c452e2 100644 --- a/models/sale_order.py +++ b/models/sale_order.py @@ -49,8 +49,7 @@ class SaleOrder(models.Model): def _get_reward_lines(self): self.ensure_one() - reward_products = self.applied_coupon_ids.mapped('program_id').mapped('discount_line_product_id') - return self.order_line.filtered(lambda line: line.product_id in reward_products) + return self.order_line.filtered(lambda line: line.is_reward_line) def _is_reward_in_order_lines(self, program): self.ensure_one()