From cd65f8bdb201401eec7a4beea40f016b244ded23 Mon Sep 17 00:00:00 2001 From: "Loukas Wets (lowe)" Date: Wed, 12 Apr 2023 14:11:22 +0000 Subject: [PATCH] [IMP] point_of_sale,pos_loyalty: gift card info notification empty cart When a valid gift card is added in a empty cart, the pos will display a notification of the resume of the gift card. We also made the notification component to preserve white space. Task-3265311 closes odoo/odoo#118609 Signed-off-by: Joseph Caburnay (jcb) --- .../static/src/app/notification/notification.scss | 4 ++++ addons/pos_loyalty/static/src/js/Loyalty.js | 13 +++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/addons/point_of_sale/static/src/app/notification/notification.scss b/addons/point_of_sale/static/src/app/notification/notification.scss index 5f4a172f7dd..90f050980b8 100644 --- a/addons/point_of_sale/static/src/app/notification/notification.scss +++ b/addons/point_of_sale/static/src/app/notification/notification.scss @@ -22,4 +22,8 @@ padding: 16px; margin: .5rem; font-size: 1rem; + + span { + white-space: pre-line; + } } diff --git a/addons/pos_loyalty/static/src/js/Loyalty.js b/addons/pos_loyalty/static/src/js/Loyalty.js index 2e14363e96d..1cb3d06bd0c 100644 --- a/addons/pos_loyalty/static/src/js/Loyalty.js +++ b/addons/pos_loyalty/static/src/js/Loyalty.js @@ -7,6 +7,7 @@ import { roundDecimals, roundPrecision } from "@web/core/utils/numbers"; import { _t } from "@web/core/l10n/translation"; import { patch } from "@web/core/utils/patch"; import { ConfirmPopup } from "@point_of_sale/js/Popups/ConfirmPopup"; +import { sprintf } from "@web/core/utils/strings"; // FIXME: Perhaps MutexedDropPrevious can be replaced by the new KeepLast. // > This might require thorough investigation on how _updateRewards work. @@ -1579,6 +1580,7 @@ patch(Order.prototype, "pos_loyalty.Order", { return rule.mode === "with_code" && (rule.promo_barcode === code || rule.code === code); }); let claimableRewards = null; + let coupon = null; if (rule) { if (this.codeActivatedProgramRules.includes(rule.id)) { return _t("That promo code program has already been activated."); @@ -1610,7 +1612,7 @@ patch(Order.prototype, "pos_loyalty.Order", { return _t("Unpaid gift card rejected."); } } - const coupon = new PosLoyaltyCard( + coupon = new PosLoyaltyCard( code, payload.coupon_id, payload.program_id, @@ -1634,12 +1636,19 @@ patch(Order.prototype, "pos_loyalty.Order", { this._updateRewards(); } } + if (!rule && this.orderlines.length === 0 && coupon) { + return sprintf( + _t("Gift Card: %s\nBalance: %s"), + code, + this.pos.format_currency(coupon.balance) + ); + } return true; }, async activateCode(code) { const res = await this._activateCode(code); if (res !== true) { - this.pos.env.services.pos_notification.add(res); + this.pos.env.services.pos_notification.add(res, 5000); } }, isProgramsResettable() {