From 3f51e45b84f791cc8fcca7de516656cf45975141 Mon Sep 17 00:00:00 2001 From: roen-odoo Date: Mon, 6 Nov 2023 15:25:32 +0000 Subject: [PATCH] =?UTF-8?q?[FIX]=20pos=5Fcoupon:=20remove=200=E2=82=AC=20r?= =?UTF-8?q?eward=20from=20the=20list=20of=20rewards?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Current behavior: When you use a coupon that gives a free product combined with a promo that gives 50% discount. The reward of 50% disappears when you add the free product. Steps to reproduce: - Create 2 program with no conditions : - One that gives 50% discount on all products with a code - One that gives a free product A - Make sure product A has a tax - Open PoS - Add a product with no tax to the order - Apply the 50% discount - Add product A - The reward of 50% disappears Note: This happens because we try to apply a 50% discount on amount that is 0 wich leads to a reward with a NaN amount. Wich makes the reward for the program disappears, because here (https://github.com/odoo/odoo/blob/15.0/addons/pos_coupon/static/src/js/coupon.js#L624) currentMaxKey is null. opw-3529959 closes odoo/odoo#142527 X-original-commit: 9be0955218b5584f27a75b401946a853ac2588ae Signed-off-by: Vlad Stroia (vlst) Signed-off-by: Robin Engels (roen) --- .../static/tests/tours/PosLoyaltyTour.js | 14 +++++ addons/pos_loyalty/tests/test_frontend.py | 63 +++++++++++++++++++ 2 files changed, 77 insertions(+) diff --git a/addons/pos_loyalty/static/tests/tours/PosLoyaltyTour.js b/addons/pos_loyalty/static/tests/tours/PosLoyaltyTour.js index 8d71a90f181..d6fa3f0d628 100644 --- a/addons/pos_loyalty/static/tests/tours/PosLoyaltyTour.js +++ b/addons/pos_loyalty/static/tests/tours/PosLoyaltyTour.js @@ -254,3 +254,17 @@ registry.category("web_tour.tours").add("PosLoyaltyTour7", { PosLoyalty.orderTotalIs("90"), ].flat(), }); + +registry.category("web_tour.tours").add('PosLoyaltyTour8', { + test: true, + url: '/pos/web', + steps: () => + [ + ProductScreen.confirmOpeningPopup(), + ProductScreen.clickHomeCategory(), + + ProductScreen.clickDisplayedProduct('Product B'), + ProductScreen.clickDisplayedProduct('Product A'), + ProductScreen.totalAmountIs('50.00'), + ].flat(), +}); diff --git a/addons/pos_loyalty/tests/test_frontend.py b/addons/pos_loyalty/tests/test_frontend.py index 47c1f7e60b3..0742f386690 100644 --- a/addons/pos_loyalty/tests/test_frontend.py +++ b/addons/pos_loyalty/tests/test_frontend.py @@ -1259,3 +1259,66 @@ class TestUi(TestPointOfSaleHttpCommon): "PosLoyaltyPromotion", login="pos_user", ) + + def test_promo_with_free_product(self): + self.env['loyalty.program'].search([]).write({'active': False}) + self.tax01 = self.env["account.tax"].create({ + "name": "C01 Tax", + "amount": "15.00", + }) + self.product_a = self.env["product.product"].create( + { + "name": "Product A", + "type": "product", + "list_price": 100, + "available_in_pos": True, + "taxes_id": [(6, 0, self.tax01.ids)], + } + ) + self.product_b = self.env["product.product"].create( + { + "name": "Product B", + "type": "product", + "list_price": 100, + "available_in_pos": True, + "taxes_id": False, + } + ) + self.free_product = self.env['loyalty.program'].create({ + 'name': 'Free Product A', + 'program_type': 'promotion', + 'trigger': 'auto', + 'applies_on': 'current', + 'rule_ids': [(0, 0, { + 'reward_point_mode': 'unit', + 'minimum_qty': 0, + })], + 'reward_ids': [(0, 0, { + 'reward_type': 'product', + 'reward_product_id': self.product_a.id, + 'reward_product_qty': 1, + 'required_points': 1, + })], + }) + self.env['loyalty.program'].create({ + 'name': 'Discount 50%', + 'program_type': 'promotion', + 'trigger': 'auto', + 'applies_on': 'current', + 'rule_ids': [(0, 0, { + 'reward_point_mode': 'order', + 'reward_point_amount': 1, + })], + 'reward_ids': [(0, 0, { + 'reward_type': 'discount', + 'required_points': 1, + 'discount': 50, + 'discount_mode': 'percent', + })], + }) + self.main_pos_config.open_ui() + self.start_tour( + "/pos/web?config_id=%d" % self.main_pos_config.id, + "PosLoyaltyTour8", + login="pos_user", + )