From 6e57324affac12ee94e1c7b5280f749a987d78e1 Mon Sep 17 00:00:00 2001 From: "Pedram (PEBR)" Date: Fri, 18 Aug 2023 11:08:53 +0000 Subject: [PATCH] [FIX] pos_loyalty: apply rewards for coupon programs without rules For loyalty programs of type 'coupons' with no rules defined, the points were not being calculated correctly in the PoS. The pointsForPrograms function was returning an empty list [] when no rules exist. This caused _getRealCouponPoints to skip calculation. This commit checks the program type and returns the points if it is 'coupons'. opw-3457550 closes odoo/odoo#133445 X-original-commit: 25ff280dfbec7e6d6f1c0a345e1902a2ab5c0774 Signed-off-by: Joseph Caburnay (jcb) Signed-off-by: Pedram Bi Ria (pebr) --- .../static/src/overrides/models/loyalty.js | 2 +- .../static/tests/tours/PosLoyaltyTour.js | 17 ++++++++ addons/pos_loyalty/tests/test_frontend.py | 42 +++++++++++++++++++ 3 files changed, 60 insertions(+), 1 deletion(-) diff --git a/addons/pos_loyalty/static/src/overrides/models/loyalty.js b/addons/pos_loyalty/static/src/overrides/models/loyalty.js index 6d60692bb8b..8a1c00c2d0b 100644 --- a/addons/pos_loyalty/static/src/overrides/models/loyalty.js +++ b/addons/pos_loyalty/static/src/overrides/models/loyalty.js @@ -869,7 +869,7 @@ patch(Order.prototype, { } } } - const res = points ? [{ points }] : []; + const res = (points || program.program_type === 'coupons') ? [{ points }] : []; if (splitPoints.length) { res.push(...splitPoints); } diff --git a/addons/pos_loyalty/static/tests/tours/PosLoyaltyTour.js b/addons/pos_loyalty/static/tests/tours/PosLoyaltyTour.js index bd8601dcbaf..126c02c9503 100644 --- a/addons/pos_loyalty/static/tests/tours/PosLoyaltyTour.js +++ b/addons/pos_loyalty/static/tests/tours/PosLoyaltyTour.js @@ -263,3 +263,20 @@ registry return getSteps(); } }); + +registry + .category("web_tour.tours") + .add("PosLoyaltyTour7", { + test: true, + url: "/pos/web", + steps: () => { + ProductScreen.do.confirmOpeningPopup(); + ProductScreen.do.clickHomeCategory(); + + ProductScreen.exec.addOrderline('Test Product', '1'); + PosLoyalty.check.orderTotalIs('100'); + PosLoyalty.do.enterCode('abcda'); + PosLoyalty.check.orderTotalIs('90'); + return getSteps(); + } + }); diff --git a/addons/pos_loyalty/tests/test_frontend.py b/addons/pos_loyalty/tests/test_frontend.py index 2669061b0fc..1e963b3ce1c 100644 --- a/addons/pos_loyalty/tests/test_frontend.py +++ b/addons/pos_loyalty/tests/test_frontend.py @@ -1080,3 +1080,45 @@ class TestUi(TestPointOfSaleHttpCommon): "PosLoyaltyTour6", login="pos_user", ) + + def test_coupon_program_without_rules(self): + self.env['loyalty.program'].search([]).write({'active': False}) + + self.env["product.product"].create( + { + "name": "Test Product", + "type": "product", + "list_price": 100, + "available_in_pos": True, + "taxes_id": False, + } + ) + + # creating a coupon program without any rule + loyalty_program = self.env['loyalty.program'].create({ + 'name': 'Coupon Program without rules', + 'program_type': 'coupons', + 'trigger': 'with_code', + 'applies_on': 'current', + 'pos_ok': True, + 'rule_ids': [], + 'reward_ids': [(0, 0, { + 'reward_type': 'discount', + 'discount': 10, + 'discount_mode': 'percent', + 'discount_applicability': 'order', + })], + }) + + self.env["loyalty.generate.wizard"].with_context( + {"active_id": loyalty_program.id} + ).create({"coupon_qty": 1, 'points_granted': 1}).generate_coupons() + self.coupon1 = loyalty_program.coupon_ids + self.coupon1.write({"code": "abcda"}) + + self.main_pos_config.open_ui() + self.start_tour( + "/pos/web?config_id=%d" % self.main_pos_config.id, + "PosLoyaltyTour7", + login="pos_user", + )