From e49029406c1956997e8ac2bf0c6e4d6e0d64614a Mon Sep 17 00:00:00 2001 From: "Jacky (trj)" Date: Tue, 26 Jul 2022 15:31:28 +0000 Subject: [PATCH] [FIX] point_of_sale, pos_{loyalty,mercury}: restricting key to confirm or cancel popup The "pressing a specific key to confirm/cancel a popup" behavior was added but the problem was that some popups only had one button which was either confirm or cancel. It was thus possible to close those popups by bypassing the default behavior (e.g. possible to "cancel" a popup which only has one button linked to an overridden confirm method and vice-versa). Also, we normalize the use of `confirm` and `cancel` methods in the popups so that when the specifics keys are pressed, the right behavior is executed. closes odoo/odoo#97069 X-original-commit: a14ade59744855a9dea8b16f23a3d61eb88678de Related: odoo/enterprise#29957 Signed-off-by: Joseph Caburnay (jcb) --- addons/point_of_sale/static/src/js/Chrome.js | 2 +- .../static/src/js/Popups/CashOpeningPopup.js | 22 +++---- .../static/src/js/Popups/ClosePosPopup.js | 60 ++++++++++--------- .../src/js/Popups/ControlButtonPopup.js | 3 +- .../static/src/js/Popups/ErrorPopup.js | 2 +- .../src/js/Popups/ErrorTracebackPopup.js | 1 + .../static/src/js/Popups/OrderImportPopup.js | 2 +- .../static/src/js/Popups/ProductInfoPopup.js | 1 + .../static/src/js/Popups/SelectionPopup.js | 2 +- .../src/xml/Popups/CashOpeningPopup.xml | 2 +- .../static/src/xml/Popups/ClosePosPopup.xml | 4 +- .../src/xml/Popups/OfflineErrorPopup.xml | 2 +- .../src/xml/Popups/OrderImportPopup.xml | 2 +- .../static/src/js/Popups/GiftCardPopup.js | 7 ++- .../static/src/xml/Popups/GiftCardPopup.xml | 2 +- .../static/src/js/PaymentTransactionPopup.js | 2 +- 16 files changed, 63 insertions(+), 53 deletions(-) diff --git a/addons/point_of_sale/static/src/js/Chrome.js b/addons/point_of_sale/static/src/js/Chrome.js index 008ebe38ba3..6512b3abd00 100644 --- a/addons/point_of_sale/static/src/js/Chrome.js +++ b/addons/point_of_sale/static/src/js/Chrome.js @@ -245,7 +245,7 @@ odoo.define('point_of_sale.Chrome', function(require) { openCashControl() { if (this.shouldShowCashControl()) { - this.showPopup('CashOpeningPopup', { cancelKey: false }); + this.showPopup('CashOpeningPopup'); } } diff --git a/addons/point_of_sale/static/src/js/Popups/CashOpeningPopup.js b/addons/point_of_sale/static/src/js/Popups/CashOpeningPopup.js index de6fb069a16..a42e56b2f69 100644 --- a/addons/point_of_sale/static/src/js/Popups/CashOpeningPopup.js +++ b/addons/point_of_sale/static/src/js/Popups/CashOpeningPopup.js @@ -16,6 +16,17 @@ odoo.define('point_of_sale.CashOpeningPopup', function(require) { displayMoneyDetailsPopup: false, }); } + //@override + async confirm() { + this.env.pos.bank_statement.balance_start = this.state.openingCash; + this.env.pos.pos_session.state = 'opened'; + this.rpc({ + model: 'pos.session', + method: 'set_cashbox_pos', + args: [this.env.pos.pos_session.id, this.state.openingCash, this.state.notes], + }); + super.confirm(); + } openDetailsPopup() { this.state.openingCash = 0; this.state.notes = ""; @@ -24,16 +35,6 @@ odoo.define('point_of_sale.CashOpeningPopup', function(require) { closeDetailsPopup() { this.state.displayMoneyDetailsPopup = false; } - startSession() { - this.env.pos.bank_statement.balance_start = this.state.openingCash; - this.env.pos.pos_session.state = 'opened'; - this.rpc({ - model: 'pos.session', - method: 'set_cashbox_pos', - args: [this.env.pos.pos_session.id, this.state.openingCash, this.state.notes], - }); - this.cancel(); // close popup - } updateCashOpening({ total, moneyDetailsNotes }) { this.state.openingCash = total; if (moneyDetailsNotes) { @@ -49,6 +50,7 @@ odoo.define('point_of_sale.CashOpeningPopup', function(require) { } CashOpeningPopup.template = 'CashOpeningPopup'; + CashOpeningPopup.defaultProps = { cancelKey: false }; Registries.Component.add(CashOpeningPopup); return CashOpeningPopup; diff --git a/addons/point_of_sale/static/src/js/Popups/ClosePosPopup.js b/addons/point_of_sale/static/src/js/Popups/ClosePosPopup.js index f7617372029..63419c95f0a 100644 --- a/addons/point_of_sale/static/src/js/Popups/ClosePosPopup.js +++ b/addons/point_of_sale/static/src/js/Popups/ClosePosPopup.js @@ -53,7 +53,7 @@ odoo.define('point_of_sale.ClosePosPopup', function(require) { } Object.assign(this.state, state); } catch (error) { - this.cancel(); + super.cancel(); if (identifyError(error) instanceof ConnectionLostError) { this.showPopup('ErrorPopup', { title: this.env._t('Network Error'), @@ -64,6 +64,36 @@ odoo.define('point_of_sale.ClosePosPopup', function(require) { } } } + //@override + async confirm() { + if (!this.cashControl || !this.hasDifference()) { + this.closeSession(); + } else if (this.hasUserAuthority()) { + const { confirmed } = await this.showPopup('ConfirmPopup', { + title: this.env._t('Payments Difference'), + body: this.env._t('Do you want to accept payments difference and post a profit/loss journal entry?'), + }); + if (confirmed) { + this.closeSession(); + } + } else { + await this.showPopup('ConfirmPopup', { + title: this.env._t('Payments Difference'), + body: _.str.sprintf( + this.env._t('The maximum difference allowed is %s.\n\ + Please contact your manager to accept the closing difference.'), + this.env.pos.format_currency(this.amountAuthorizedDiff) + ), + confirmText: this.env._t('OK'), + }) + } + } + //@override + async cancel() { + if (this.canCancel()) { + super.cancel(); + } + } openDetailsPopup() { this.state.payments[this.defaultCashDetails.id].counted = 0; this.state.payments[this.defaultCashDetails.id].difference = -this.defaultCashDetails.amount; @@ -110,37 +140,9 @@ odoo.define('point_of_sale.ClosePosPopup', function(require) { const absDifferences = Object.entries(this.state.payments).map(pm => Math.abs(pm[1].difference)); return this.isManager || this.amountAuthorizedDiff == null || Math.max(...absDifferences) <= this.amountAuthorizedDiff; } - async onCloseSession() { - if (!this.cashControl || !this.hasDifference()) { - this.closeSession(); - } else if (this.hasUserAuthority()) { - const { confirmed } = await this.showPopup('ConfirmPopup', { - title: this.env._t('Payments Difference'), - body: this.env._t('Do you want to accept payments difference and post a profit/loss journal entry?'), - }); - if (confirmed) { - this.closeSession(); - } - } else { - await this.showPopup('ConfirmPopup', { - title: this.env._t('Payments Difference'), - body: _.str.sprintf( - this.env._t('The maximum difference allowed is %s.\n\ - Please contact your manager to accept the closing difference.'), - this.env.pos.format_currency(this.amountAuthorizedDiff) - ), - confirmText: this.env._t('OK'), - }) - } - } canCancel() { return true; } - cancelPopup() { - if (this.canCancel()) { - this.cancel(); - } - } closePos() { this.trigger('close-pos'); } diff --git a/addons/point_of_sale/static/src/js/Popups/ControlButtonPopup.js b/addons/point_of_sale/static/src/js/Popups/ControlButtonPopup.js index 2da01ee821e..924accf4b7f 100644 --- a/addons/point_of_sale/static/src/js/Popups/ControlButtonPopup.js +++ b/addons/point_of_sale/static/src/js/Popups/ControlButtonPopup.js @@ -18,7 +18,8 @@ odoo.define('point_of_sale.ControlButtonPopup', function(require) { ControlButtonPopup.template = 'ControlButtonPopup'; ControlButtonPopup.defaultProps = { cancelText: _lt('Back'), - controlButtons: [] + controlButtons: [], + confirmKey: false, }; Registries.Component.add(ControlButtonPopup); diff --git a/addons/point_of_sale/static/src/js/Popups/ErrorPopup.js b/addons/point_of_sale/static/src/js/Popups/ErrorPopup.js index 3d2bfc0f311..8300b6a5749 100644 --- a/addons/point_of_sale/static/src/js/Popups/ErrorPopup.js +++ b/addons/point_of_sale/static/src/js/Popups/ErrorPopup.js @@ -18,9 +18,9 @@ odoo.define('point_of_sale.ErrorPopup', function(require) { ErrorPopup.template = 'ErrorPopup'; ErrorPopup.defaultProps = { confirmText: _lt('Ok'), - cancelText: _lt('Cancel'), title: _lt('Error'), body: '', + cancelKey: false, }; Registries.Component.add(ErrorPopup); diff --git a/addons/point_of_sale/static/src/js/Popups/ErrorTracebackPopup.js b/addons/point_of_sale/static/src/js/Popups/ErrorTracebackPopup.js index b9ca658e855..c8990ad5578 100644 --- a/addons/point_of_sale/static/src/js/Popups/ErrorTracebackPopup.js +++ b/addons/point_of_sale/static/src/js/Popups/ErrorTracebackPopup.js @@ -32,6 +32,7 @@ odoo.define('point_of_sale.ErrorTracebackPopup', function(require) { ErrorTracebackPopup.defaultProps = { confirmText: _lt('Ok'), cancelText: _lt('Cancel'), + confirmKey: false, title: _lt('Error with Traceback'), body: '', exitButtonIsShown: false, diff --git a/addons/point_of_sale/static/src/js/Popups/OrderImportPopup.js b/addons/point_of_sale/static/src/js/Popups/OrderImportPopup.js index 8395bf28c81..951957819a5 100644 --- a/addons/point_of_sale/static/src/js/Popups/OrderImportPopup.js +++ b/addons/point_of_sale/static/src/js/Popups/OrderImportPopup.js @@ -18,7 +18,7 @@ odoo.define('point_of_sale.OrderImportPopup', function(require) { OrderImportPopup.template = 'OrderImportPopup'; OrderImportPopup.defaultProps = { confirmText: _lt('Ok'), - cancelText: _lt('Cancel'), + cancelKey: false, body: '', }; diff --git a/addons/point_of_sale/static/src/js/Popups/ProductInfoPopup.js b/addons/point_of_sale/static/src/js/Popups/ProductInfoPopup.js index a066cc7db11..ceaadff49b3 100644 --- a/addons/point_of_sale/static/src/js/Popups/ProductInfoPopup.js +++ b/addons/point_of_sale/static/src/js/Popups/ProductInfoPopup.js @@ -71,5 +71,6 @@ odoo.define('point_of_sale.ProductInfoPopup', function(require) { } ProductInfoPopup.template = 'ProductInfoPopup'; + ProductInfoPopup.defaultProps= { confirmKey: false }; Registries.Component.add(ProductInfoPopup); }); diff --git a/addons/point_of_sale/static/src/js/Popups/SelectionPopup.js b/addons/point_of_sale/static/src/js/Popups/SelectionPopup.js index 944fb7c11fa..c74e0fc9c90 100644 --- a/addons/point_of_sale/static/src/js/Popups/SelectionPopup.js +++ b/addons/point_of_sale/static/src/js/Popups/SelectionPopup.js @@ -46,11 +46,11 @@ odoo.define('point_of_sale.SelectionPopup', function (require) { } SelectionPopup.template = 'SelectionPopup'; SelectionPopup.defaultProps = { - confirmText: _lt('Confirm'), cancelText: _lt('Cancel'), title: _lt('Select'), body: '', list: [], + confirmKey: false, }; Registries.Component.add(SelectionPopup); diff --git a/addons/point_of_sale/static/src/xml/Popups/CashOpeningPopup.xml b/addons/point_of_sale/static/src/xml/Popups/CashOpeningPopup.xml index 98a6d5f7705..5003319956b 100644 --- a/addons/point_of_sale/static/src/xml/Popups/CashOpeningPopup.xml +++ b/addons/point_of_sale/static/src/xml/Popups/CashOpeningPopup.xml @@ -18,7 +18,7 @@