diff --git a/addons/pos_loyalty/static/src/overrides/models/pos_store.js b/addons/pos_loyalty/static/src/overrides/models/pos_store.js index 7202451880b..9cabd838ebe 100644 --- a/addons/pos_loyalty/static/src/overrides/models/pos_store.js +++ b/addons/pos_loyalty/static/src/overrides/models/pos_store.js @@ -95,7 +95,18 @@ patch(PosStore.prototype, { return false; } const trimmedCode = code.trim(); - if (trimmedCode && trimmedCode.startsWith("044")) { + let nomenclatureRules = this.barcodeReader.parser.nomenclature.rules; + if (this.barcodeReader.fallbackParser) { + nomenclatureRules = nomenclatureRules.concat( + this.barcodeReader.fallbackParser.nomenclature.rules + ); + } + const couponRules = nomenclatureRules.filter((rule) => rule.type === "coupon"); + const isValidCoupon = couponRules.some((rule) => { + let patterns = rule.pattern.split("|"); + return patterns.some((pattern) => trimmedCode.startsWith(pattern)); + }); + if (isValidCoupon) { // check if the code exist in the database // if so, use its balance, otherwise, use the unit price of the gift card product const fetchedGiftCard = await this.orm.searchRead( diff --git a/addons/pos_loyalty/static/tests/tours/GiftCardProgramTours.js b/addons/pos_loyalty/static/tests/tours/GiftCardProgramTours.js index 11694dc6b4d..5919ddb8dae 100644 --- a/addons/pos_loyalty/static/tests/tours/GiftCardProgramTours.js +++ b/addons/pos_loyalty/static/tests/tours/GiftCardProgramTours.js @@ -48,18 +48,18 @@ registry.category("web_tour.tours").add("GiftCardProgramScanUseTour", { // Pay the 5$ gift card. ProductScreen.clickDisplayedProduct("Gift Card"), TextInputPopup.isShown(), - TextInputPopup.inputText("044123456"), + TextInputPopup.inputText("043123456"), TextInputPopup.clickConfirm(), PosLoyalty.orderTotalIs("5.00"), PosLoyalty.finalizeOrder("Cash", "5"), // Partially use the gift card. (4$) ProductScreen.addOrderline("Desk Pad", "2", "2", "4.0"), - PosLoyalty.enterCode("044123456"), + PosLoyalty.enterCode("043123456"), PosLoyalty.orderTotalIs("0.00"), PosLoyalty.finalizeOrder("Cash", "0"), // Use the remaining of the gift card. (5$ - 4$ = 1$) ProductScreen.addOrderline("Whiteboard Pen", "6", "6", "36.0"), - PosLoyalty.enterCode("044123456"), + PosLoyalty.enterCode("043123456"), PosLoyalty.orderTotalIs("35.00"), PosLoyalty.finalizeOrder("Cash", "35"), ].flat(), diff --git a/addons/pos_loyalty/tests/test_frontend.py b/addons/pos_loyalty/tests/test_frontend.py index 93d3206a2e4..de7e4f51713 100644 --- a/addons/pos_loyalty/tests/test_frontend.py +++ b/addons/pos_loyalty/tests/test_frontend.py @@ -543,6 +543,11 @@ class TestUi(TestPointOfSaleHttpCommon): (4, self.env.ref('stock.group_stock_user').id), ] }) + # set the nomenclature to GS1 + barcodes_gs1_nomenclature = self.env.ref("barcodes_gs1_nomenclature.default_gs1_nomenclature") + self.main_pos_config.company_id.write({ + 'nomenclature_id': barcodes_gs1_nomenclature.id + }) LoyaltyProgram = self.env['loyalty.program'] # Deactivate all other programs to avoid interference @@ -558,7 +563,7 @@ class TestUi(TestPointOfSaleHttpCommon): {"active_id": gift_card_program.id} ).create({"coupon_qty": 1, 'points_granted': 5}).generate_coupons() # Change the code of the gift card. - gift_card_program.coupon_ids.code = '044123456' + gift_card_program.coupon_ids.code = '043123456' # Run the tour. It will pay the gift card and use it. self.start_tour( "/pos/web?config_id=%d" % self.main_pos_config.id,