diff options
| author | Andrea Grazioso (agr-odoo) <agr@odoo.com> | 2020-06-16 09:02:44 +0000 |
|---|---|---|
| committer | Andrea Grazioso (agr-odoo) <agr@odoo.com> | 2020-06-22 11:51:30 +0000 |
| commit | 1c856c779b5bc6f22a864ad696c98f4eeb7a7403 (patch) | |
| tree | 8bbdd3e8a90ec8b60f45fd864d4ac278f88ce51e /addons | |
| parent | 4b7a4d4f0ce6f1c2117e97e49d85e14ce61420e1 (diff) | |
[FIX] sale_coupon: fix order total price for reward computation
Create a promotion program with conditions:
- Minimum product quantity (ex 2)
- Minimum purchase in currency (ex 500$ tax excluded)
- Auto apply
- On current order
- with reward:
-- Free product (Free Prod A)
-- 1 Quantity
Create a sale order. Insert 3x ProdA @ 1000$. Click on "promotions".
Nothing will occur because the minimum order amount for applying the reward is
calculated removing from the order the product associated with the
reward. This removed all of the products from the order, so the result is 0.
Fixing by subtracting just the amount specified in the reward program.
opw-2274316
closes odoo/odoo#53407
X-original-commit: 804461fb1353c931986eeae94bd3ad8465b604e7
Signed-off-by: Nicolas Martinelli (nim) <nim@odoo.com>
Diffstat (limited to 'addons')
| -rw-r--r-- | addons/sale_coupon/models/sale_order.py | 2 | ||||
| -rw-r--r-- | addons/sale_coupon/tests/test_program_numbers.py | 43 |
2 files changed, 44 insertions, 1 deletions
diff --git a/addons/sale_coupon/models/sale_order.py b/addons/sale_coupon/models/sale_order.py index bca35bd8879..fd979d0524b 100644 --- a/addons/sale_coupon/models/sale_order.py +++ b/addons/sale_coupon/models/sale_order.py @@ -89,7 +89,7 @@ class SaleOrder(models.Model): # 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)) + order_total = sum(order_lines.mapped('price_total')) - (program.reward_product_quantity * program.reward_product_id.lst_price) 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) diff --git a/addons/sale_coupon/tests/test_program_numbers.py b/addons/sale_coupon/tests/test_program_numbers.py index 91ce9e23dbd..f29b4543079 100644 --- a/addons/sale_coupon/tests/test_program_numbers.py +++ b/addons/sale_coupon/tests/test_program_numbers.py @@ -729,3 +729,46 @@ class TestSaleCouponProgramNumbers(TestSaleCouponCommon): # TOTAL | 78.34 | 87.00 | 8.66 self.assertEqual(order.amount_total, 87.00, "Total untaxed should be as per above comment") self.assertEqual(order.amount_untaxed, 78.34, "Total with taxes should be as per above comment") + + def test_program_numbers_free_prod_with_min_amount_and_qty_on_same_prod(self): + # This test focus on giving a free product based on both + # minimum amount and quantity condition on an + # auto applied promotion program + + order = self.empty_order + self.p3 = self.env['coupon.program'].create({ + 'name': 'Buy 2 Chairs, get 1 free', + 'promo_code_usage': 'no_code_needed', + 'reward_type': 'product', + 'program_type': 'promotion_program', + 'reward_product_id': self.conferenceChair.id, + 'rule_min_quantity': 2, + 'rule_minimum_amount': self.conferenceChair.lst_price * 2, + 'rule_products_domain': '[["sale_ok","=",True], ["id","=", %d]]' % self.conferenceChair.id, + }) + sol1 = self.env['sale.order.line'].create({ + 'product_id': self.conferenceChair.id, + 'name': 'Conf Chair', + 'product_uom_qty': 2.0, + 'order_id': order.id, + }) + sol2 = self.env['sale.order.line'].create({ + 'product_id': self.drawerBlack.id, + 'name': 'Drawer', + 'product_uom_qty': 1.0, + 'order_id': order.id, + }) # dummy line + + order.recompute_coupon_lines() + self.assertEqual(len(order.order_line.ids), 2, "The promotion lines should not be applied") + sol1.write({'product_uom_qty': 3.0}) + order.recompute_coupon_lines() + self.assertEqual(len(order.order_line.ids), 3, "The promotion lines should have been added") + self.assertEqual(order.amount_total, self.conferenceChair.lst_price * (sol1.product_uom_qty - 1) + self.drawerBlack.lst_price * sol2.product_uom_qty, "The promotion line was not applied to the amount total") + sol2.unlink() + order.recompute_coupon_lines() + self.assertEqual(len(order.order_line.ids), 2, "The other product should not affect the promotion") + self.assertEqual(order.amount_total, self.conferenceChair.lst_price * (sol1.product_uom_qty - 1), "The promotion line was not applied to the amount total") + sol1.write({'product_uom_qty': 2.0}) + order.recompute_coupon_lines() + self.assertEqual(len(order.order_line.ids), 1, "The promotion lines should have been removed") |
