From d461fcef5c8475360b24e2b0ecb94c4a510f14db Mon Sep 17 00:00:00 2001 From: roen-odoo Date: Fri, 7 Jul 2023 12:45:05 +0000 Subject: [PATCH] [FIX] pos_coupon: Make sure loyalty rewards are considered as rewards MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Current behavior: When a loyalty reward was applied with a promotion program, a promotion reward was added with a -Infinity value. Steps to reproduce: - Create a loyalty program with a reward of 5€ fixed amount for 50 points - Create a promotion program with a reward of 10% discount - Open a pos session, select a customer (and add points to the loyalty program if needed). - Add a product to the order, the 10% discount should be applied - Now click on the reward button to apply the loyalty reward - The loyalty reward is correctly applied, but a new promotion reward is added with a -Infinity value. opw-3297817 closes odoo/odoo#133550 X-original-commit: ee60da301209c84264d706b9d16e45af541a3bbf Signed-off-by: Joseph Caburnay (jcb) Signed-off-by: Robin Engels (roen) --- .../tours/PosLoyaltyLoyaltyProgramTour.js | 17 ++++ addons/pos_loyalty/tests/test_frontend.py | 79 +++++++++++++++++++ 2 files changed, 96 insertions(+) diff --git a/addons/pos_loyalty/static/tests/tours/PosLoyaltyLoyaltyProgramTour.js b/addons/pos_loyalty/static/tests/tours/PosLoyaltyLoyaltyProgramTour.js index bec6a15c66f..cf12de26602 100644 --- a/addons/pos_loyalty/static/tests/tours/PosLoyaltyLoyaltyProgramTour.js +++ b/addons/pos_loyalty/static/tests/tours/PosLoyaltyLoyaltyProgramTour.js @@ -179,3 +179,20 @@ registry.category("web_tour.tours").add("PosLoyaltyLoyaltyProgram3", { return getSteps(); }, }); + +registry.category("web_tour.tours").add("PosLoyaltyPromotion", { + test: true, + url: "/pos/web", + steps: () => { + startSteps(); + + ProductScreen.do.clickHomeCategory(); + ProductScreen.do.confirmOpeningPopup(); + + ProductScreen.do.clickPartnerButton(); + ProductScreen.do.clickCustomer('AAA Partner'); + ProductScreen.exec.addOrderline('Test Product 1', '1.00', '100'); + ProductScreen.check.totalAmountIs('80.00'); + return getSteps(); + } +}); diff --git a/addons/pos_loyalty/tests/test_frontend.py b/addons/pos_loyalty/tests/test_frontend.py index 0b52d21d569..47c1f7e60b3 100644 --- a/addons/pos_loyalty/tests/test_frontend.py +++ b/addons/pos_loyalty/tests/test_frontend.py @@ -1180,3 +1180,82 @@ class TestUi(TestPointOfSaleHttpCommon): "PosLoyaltySpecificDiscountWithRewardProductDomainTour", login="pos_user", ) + + def test_promotion_program_with_loyalty_program(self): + """ + - Create a promotion with a discount of 10% + - Create a loyalty program with a fixed discount of 10€ + - Apply both programs to the order + - Check that no "infinity" discount is applied + """ + self.env['loyalty.program'].search([]).write({'active': False}) + self.promo_program = self.env['loyalty.program'].create({ + 'name': 'Promo Program', + 'program_type': 'promotion', + 'pos_ok': True, + 'rule_ids': [(0, 0, { + 'minimum_amount': 0, + 'minimum_qty': 0 + })], + 'reward_ids': [(0, 0, { + 'reward_type': 'discount', + 'discount': 10, + 'discount_mode': 'percent', + 'discount_applicability': 'order', + })], + }) + + self.discount_product = self.env["product.product"].create( + { + "name": "Discount Product", + "type": "service", + "list_price": 0, + "available_in_pos": True, + "taxes_id": False, + } + ) + + self.test_product = self.env["product.product"].create( + { + "name": "Test Product 1", + "type": "product", + "list_price": 100, + "available_in_pos": True, + "taxes_id": False, + } + ) + + self.loyalty_program = self.env["loyalty.program"].create( + { + "name": "Loyalty Program", + "program_type": "loyalty", + "pos_ok": True, + "rule_ids": [(0, 0, { + "minimum_amount": 1, + "minimum_qty": 1, + "reward_point_mode": "order", + "reward_point_amount": 500, + })], + "reward_ids": [(0, 0, { + "required_points": 500, + "reward_type": "discount", + "discount": "10", + "discount_mode": "per_order", + })], + } + ) + + partner = self.env['res.partner'].create({'name': 'AAA Partner'}) + self.env['loyalty.card'].create({ + 'partner_id': partner.id, + 'program_id': self.loyalty_program.id, + 'points': 500, + }) + + self.main_pos_config.open_ui() + + self.start_tour( + "/pos/web?config_id=%d" % self.main_pos_config.id, + "PosLoyaltyPromotion", + login="pos_user", + )