From cfa93cabd191df9aa235b73ffd14d16460aca5f1 Mon Sep 17 00:00:00 2001 From: Joseph Caburnay Date: Tue, 7 Sep 2021 11:21:12 +0000 Subject: [PATCH] [FIX] pos_coupon: warn user before deleting an active program in the order It is possible that the user can mistakenly delete a reward line which completely deactivates the program in that order. We provide a warning message to the user to make sure of his intent. Part-of: odoo/odoo#77903 --- .../pos_coupon/static/src/js/ProductScreen.js | 21 +++++++++++++++++++ .../src/js/tours/PosCouponTourMethods.js | 8 ++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/addons/pos_coupon/static/src/js/ProductScreen.js b/addons/pos_coupon/static/src/js/ProductScreen.js index a70a02c0689..21714ed1be8 100644 --- a/addons/pos_coupon/static/src/js/ProductScreen.js +++ b/addons/pos_coupon/static/src/js/ProductScreen.js @@ -16,6 +16,27 @@ odoo.define('pos_coupon.ProductScreen', function (require) { _onCouponScan(code) { this.currentOrder.activateCode(code.base_code); } + async _updateSelectedOrderline(event) { + const selectedLine = this.currentOrder.get_selected_orderline(); + if (selectedLine && selectedLine.is_program_reward && event.detail.key === 'Backspace') { + const program = this.env.pos.coupon_programs_by_id[selectedLine.program_id] + const { confirmed } = await this.showPopup('ConfirmPopup', { + title: this.env._t('Deactivating program'), + body: _.str.sprintf( + this.env._t('Are you sure you want to deactivate %s in this order?'), + program.name + ), + cancelText: this.env._t('No'), + confirmText: this.env._t('Yes'), + }); + if (confirmed) { + event.detail.buffer = null; + } else { + return; // do nothing on the line + } + } + return super._updateSelectedOrderline(...arguments); + } /** * 1/ Perform the usual set value operation (super._setValue) if the line being modified * is not a reward line or if it is a reward line, the `val` being set is '' or 'remove' only. diff --git a/addons/pos_coupon/static/src/js/tours/PosCouponTourMethods.js b/addons/pos_coupon/static/src/js/tours/PosCouponTourMethods.js index 5d324b649ce..e507ceb9fe7 100644 --- a/addons/pos_coupon/static/src/js/tours/PosCouponTourMethods.js +++ b/addons/pos_coupon/static/src/js/tours/PosCouponTourMethods.js @@ -5,10 +5,12 @@ odoo.define('pos_coupon.tour.PosCouponTourMethods', function (require) { const { Do: ProductScreenDo } = require('point_of_sale.tour.ProductScreenTourMethods'); const { Do: PaymentScreenDo } = require('point_of_sale.tour.PaymentScreenTourMethods'); const { Do: ReceiptScreenDo } = require('point_of_sale.tour.ReceiptScreenTourMethods'); + const { Do: ChromeDo } = require('point_of_sale.tour.ChromeTourMethods'); const ProductScreen = { do: new ProductScreenDo() }; const PaymentScreen = { do: new PaymentScreenDo() }; const ReceiptScreen = { do: new ReceiptScreenDo() }; + const Chrome = { do: new ChromeDo() }; class Do { selectRewardLine(rewardName) { @@ -92,7 +94,11 @@ odoo.define('pos_coupon.tour.PosCouponTourMethods', function (require) { ]; } removeRewardLine(name) { - return [...this.do.selectRewardLine(name), ...ProductScreen.do.pressNumpad('Backspace Backspace')]; + return [ + ...this.do.selectRewardLine(name), + ...ProductScreen.do.pressNumpad('Backspace'), + ...Chrome.do.confirmPopup(), + ]; } }