From 32f7be02c09f86e18abc107b199075f03f5bcec2 Mon Sep 17 00:00:00 2001 From: roen-odoo Date: Thu, 16 Mar 2023 16:21:05 +0000 Subject: [PATCH] [FIX] pos_loyalty: correct value for gift card with discount MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Current behavior: When you sell a gift card in the PoS with a discount, the value of the gift card is not correct. For example, if you sell a gift card of 100€ with a 50% discount the customer should pay 50€ and the gift card should be worth 100€. But the customer pays 50€ and the gift card is worth 50€. Steps to reproduce: - Create a gift card program - Open a PoS session - Sell a gift card of 100€ with a 50% discount - Pay the order - The value of the giftcard should be 100€ but it is 50€ opw-3221553 closes odoo/odoo#116746 X-original-commit: 1631ab332a6c9c7ca5e1f2451a51fb663534cb8e Signed-off-by: Trinh Jacky (trj) Signed-off-by: Engels Robin (roen) --- addons/pos_loyalty/static/src/js/Loyalty.js | 11 ++++++++- .../static/src/tours/GiftCardProgramTours.js | 11 +++++++++ addons/pos_loyalty/tests/test_frontend.py | 23 +++++++++++++++++++ 3 files changed, 44 insertions(+), 1 deletion(-) diff --git a/addons/pos_loyalty/static/src/js/Loyalty.js b/addons/pos_loyalty/static/src/js/Loyalty.js index 87022c477b2..d0f854aefda 100644 --- a/addons/pos_loyalty/static/src/js/Loyalty.js +++ b/addons/pos_loyalty/static/src/js/Loyalty.js @@ -378,10 +378,15 @@ patch(Order.prototype, "pos_loyalty.Order", { wait_for_push_order() { return ( !_.isEmpty(this.couponPointChanges) || + this._has_gift_card_product() || this._get_reward_lines().length || this._super(...arguments) ); }, + _has_gift_card_product() { + const orderLines = this.get_orderlines(); + return orderLines.some((line) => line.eWalletGiftCardProgram); + }, /** * Add additional information for our ticket, such as new coupons and loyalty point gains. * @@ -925,8 +930,12 @@ patch(Order.prototype, "pos_loyalty.Order", { ) { continue; } + let price_to_use = line.get_price_with_tax(); + if (program.program_type === 'gift_card') { + price_to_use = line.price; + } const pointsPerUnit = round_precision( - (rule.reward_point_amount * line.get_price_with_tax()) / + (rule.reward_point_amount * price_to_use) / line.get_quantity(), 0.01 ); diff --git a/addons/pos_loyalty/static/src/tours/GiftCardProgramTours.js b/addons/pos_loyalty/static/src/tours/GiftCardProgramTours.js index 65297ade573..2efea68ee5a 100644 --- a/addons/pos_loyalty/static/src/tours/GiftCardProgramTours.js +++ b/addons/pos_loyalty/static/src/tours/GiftCardProgramTours.js @@ -49,3 +49,14 @@ PosLoyalty.check.orderTotalIs("35.00"); PosLoyalty.exec.finalizeOrder("Cash", "35"); registry.category("web_tour.tours").add("GiftCardProgramScanUseTour", { test: true, url: "/pos/web", steps: getSteps() }); //#endregion + +//#region GiftCardProgramCreateSetTour1 +startSteps(); +ProductScreen.do.confirmOpeningPopup(); +ProductScreen.do.clickHomeCategory(); +ProductScreen.do.clickDisplayedProduct('Gift Card'); +ProductScreen.do.pressNumpad('Disc 5 0'); +PosLoyalty.check.orderTotalIs('25.00'); +PosLoyalty.exec.finalizeOrder('Cash', '25'); +registry.category('web_tour.tours').add('GiftCardWithDiscountTour', { test: true, url: '/pos/web', steps: getSteps() }); +//#endregion diff --git a/addons/pos_loyalty/tests/test_frontend.py b/addons/pos_loyalty/tests/test_frontend.py index eef51614b1d..f047e337b54 100644 --- a/addons/pos_loyalty/tests/test_frontend.py +++ b/addons/pos_loyalty/tests/test_frontend.py @@ -815,3 +815,26 @@ class TestUi(TestPointOfSaleHttpCommon): "PosLoyaltyFreeProductTour2", login="accountman", ) + + def test_gift_card_value_with_discount(self): + """When selling a gift card with a discount, the value of the gift card + should be the amount before the discount.""" + LoyaltyProgram = self.env['loyalty.program'] + # Deactivate all other programs to avoid interference + (LoyaltyProgram.search([])).write({'pos_ok': False}) + # But activate the gift_card_product_50 and ewallet_product_50 because they're shared among new programs. + self.env.ref('loyalty.gift_card_product_50').write({'active': True}) + self.env.ref('loyalty.ewallet_product_50').write({'active': True}) + # Create programs + programs = self.create_programs([ + ('gift_card_1', 'gift_card'), + ]) + # Run the tour to topup ewallets. + self.start_tour( + "/pos/web?config_id=%d" % self.main_pos_config.id, + "GiftCardWithDiscountTour", + login="accountman", + ) + # Check the created gift cards. + self.assertEqual(len(programs['gift_card_1'].coupon_ids), 1) + self.assertEqual(programs['gift_card_1'].coupon_ids.points, 50)