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)