From dac0e87e0f4c02193fc1f19fc07eafeac7fdfd59 Mon Sep 17 00:00:00 2001 From: pedrambiria Date: Wed, 3 May 2023 19:49:15 +0000 Subject: [PATCH] [FIX] point_of_sale: enhance cash input handling This commit addresses several issues with inputting cash values in the closing and opening pop-up, particularly when the computer's locale doesn't match the Odoo instance's locale and when using the Safari browser. Previously, pressing the wrong decimal point would remove the inputted value, and the input handling was not consistent in Safari. Changes: - Added restrictions similar to the number popup - Ensured compatibility with localization settings, allowing the configured decimal point to work correctly - Improved input handling consistency across browsers, including Safari opw-3288550 closes odoo/odoo#128308 X-original-commit: c017a9f947843dbef99546e12057452be2fd5e76 Signed-off-by: Joseph Caburnay (jcb) Signed-off-by: Pedram Bi Ria (pebr) --- .../navbar/cash_move_popup/cash_move_popup.js | 17 ++++--- .../cash_move_popup/cash_move_popup.xml | 6 +-- .../app/navbar/closing_popup/closing_popup.js | 14 +++++- .../navbar/closing_popup/closing_popup.xml | 8 ++-- .../cash_opening_popup/cash_opening_popup.js | 12 ++--- .../cash_opening_popup/cash_opening_popup.xml | 6 ++- .../static/src/app/utils/hooks.js | 44 ++++++++++++++++++- .../static/src/css/popups/common.css | 21 +++++++++ addons/point_of_sale/static/src/scss/pos.scss | 5 +++ 9 files changed, 110 insertions(+), 23 deletions(-) diff --git a/addons/point_of_sale/static/src/app/navbar/cash_move_popup/cash_move_popup.js b/addons/point_of_sale/static/src/app/navbar/cash_move_popup/cash_move_popup.js index 9ede9c721e0..69883680ec6 100644 --- a/addons/point_of_sale/static/src/app/navbar/cash_move_popup/cash_move_popup.js +++ b/addons/point_of_sale/static/src/app/navbar/cash_move_popup/cash_move_popup.js @@ -10,6 +10,7 @@ import { usePos } from "@point_of_sale/app/store/pos_hook"; import { AbstractAwaitablePopup } from "@point_of_sale/app/popup/abstract_awaitable_popup"; import { ErrorPopup } from "@point_of_sale/app/errors/popups/error_popup"; +import { useValidateCashInput } from "@point_of_sale/app/utils/hooks"; export class CashMovePopup extends AbstractAwaitablePopup { static template = "point_of_sale.CashMovePopup"; @@ -27,8 +28,10 @@ export class CashMovePopup extends AbstractAwaitablePopup { amount: "", reason: "", errorMessage: "", + parsedAmount: 0, }); this.amountInput = useAutofocus({ refName: "amountInput" }); + useValidateCashInput('amountInput'); } async confirm() { let amount; @@ -114,13 +117,13 @@ export class CashMovePopup extends AbstractAwaitablePopup { this.state.errorMessage = ""; this.amountInput.el.focus(); } - async cancel() { - super.cancel(); - if ( - this.pos.config.iface_cashdrawer && - this.pos.hardwareProxy.connectionInfo.status === "connected" - ) { - this.pos.logEmployeeMessage(_t("Cash in / out"), "ACTION_CANCELLED"); + handleInputChange() { + if (this.amountInput.el.classList.contains('invalid-cash-input')) { + this.amountInput.el.parentElement.classList.add('invalid-cash-input'); + this.amountInput.el.style.border = 'none'; + return; } + this.amountInput.el.parentElement.classList.remove('invalid-cash-input'); + this.state.parsedAmount = parseFloat(this.state.amount); } } diff --git a/addons/point_of_sale/static/src/app/navbar/cash_move_popup/cash_move_popup.xml b/addons/point_of_sale/static/src/app/navbar/cash_move_popup/cash_move_popup.xml index 276d29aecc5..7e3aaf94c3c 100644 --- a/addons/point_of_sale/static/src/app/navbar/cash_move_popup/cash_move_popup.xml +++ b/addons/point_of_sale/static/src/app/navbar/cash_move_popup/cash_move_popup.xml @@ -12,7 +12,7 @@ Cash Out -