From f94d14833c3b5f9bc5916d1c4f7f71c7139e2d0b Mon Sep 17 00:00:00 2001 From: "Adrien Guilliams (adgu)" Date: Mon, 27 Nov 2023 12:11:22 +0100 Subject: [PATCH] [FIX] pos*: fix parseFloat not used correctly pos*: point_of_sale, pos_discount, pos_restaurant Prior to this commit, the money_details_popup was using the formatStrCurrency which it should not because it use the Odoo parseFloat method which accept localized number string. This commit fixes this by using the built-in parseFloat method and calling formatCurrency. This commit also adapts some parts of the code where we used the parseFloat method from the web module incorrectly. closes odoo/odoo#143782 Signed-off-by: Joseph Caburnay (jcb) --- .../payment_screen/payment_lines/payment_lines.js | 3 ++- .../utils/money_details_popup/money_details_popup.js | 3 +++ .../utils/money_details_popup/money_details_popup.xml | 2 +- .../components/discount_button/discount_button.js | 1 + .../static/src/app/tip_screen/tip_screen.js | 8 ++++++-- .../components/ticket_screen/ticket_screen.js | 10 ++++++++-- 6 files changed, 21 insertions(+), 6 deletions(-) diff --git a/addons/point_of_sale/static/src/app/screens/payment_screen/payment_lines/payment_lines.js b/addons/point_of_sale/static/src/app/screens/payment_screen/payment_lines/payment_lines.js index e9963f75a0e..2a587ef4b1b 100644 --- a/addons/point_of_sale/static/src/app/screens/payment_screen/payment_lines/payment_lines.js +++ b/addons/point_of_sale/static/src/app/screens/payment_screen/payment_lines/payment_lines.js @@ -5,6 +5,7 @@ import { NumberPopup } from "@point_of_sale/app/utils/input_popups/number_popup" import { useService } from "@web/core/utils/hooks"; import { Component, useState } from "@odoo/owl"; import { usePos } from "@point_of_sale/app/store/pos_hook"; +import { parseFloat } from "@web/views/fields/parsers"; export class PaymentScreenPaymentLines extends Component { static template = "point_of_sale.PaymentScreenPaymentLines"; @@ -30,7 +31,7 @@ export class PaymentScreenPaymentLines extends Component { if (this.ui.isSmall) { const { confirmed, payload } = await this.popup.add(NumberPopup, { title: _t("New amount"), - startingValue: parseFloat(paymentline.amount), + startingValue: paymentline.amount, isInputSelected: true, nbrDecimal: this.pos.currency.decimal_places, }); diff --git a/addons/point_of_sale/static/src/app/utils/money_details_popup/money_details_popup.js b/addons/point_of_sale/static/src/app/utils/money_details_popup/money_details_popup.js index 836fe5f3cf1..9fa4e281f3a 100644 --- a/addons/point_of_sale/static/src/app/utils/money_details_popup/money_details_popup.js +++ b/addons/point_of_sale/static/src/app/utils/money_details_popup/money_details_popup.js @@ -54,4 +54,7 @@ export class MoneyDetailsPopup extends AbstractAwaitablePopup { this.pos.logEmployeeMessage(this.props.action, "ACTION_CANCELLED"); } } + _parseFloat(value) { + return parseFloat(value); + } } diff --git a/addons/point_of_sale/static/src/app/utils/money_details_popup/money_details_popup.xml b/addons/point_of_sale/static/src/app/utils/money_details_popup/money_details_popup.xml index 66fdf062373..c20bdbfbef4 100644 --- a/addons/point_of_sale/static/src/app/utils/money_details_popup/money_details_popup.xml +++ b/addons/point_of_sale/static/src/app/utils/money_details_popup/money_details_popup.xml @@ -11,7 +11,7 @@
diff --git a/addons/pos_discount/static/src/overrides/components/discount_button/discount_button.js b/addons/pos_discount/static/src/overrides/components/discount_button/discount_button.js index 7346b5c0608..76dfae0e24e 100644 --- a/addons/pos_discount/static/src/overrides/components/discount_button/discount_button.js +++ b/addons/pos_discount/static/src/overrides/components/discount_button/discount_button.js @@ -7,6 +7,7 @@ import { NumberPopup } from "@point_of_sale/app/utils/input_popups/number_popup" import { ErrorPopup } from "@point_of_sale/app/errors/popups/error_popup"; import { Component } from "@odoo/owl"; import { usePos } from "@point_of_sale/app/store/pos_hook"; +import { parseFloat } from "@web/views/fields/parsers"; export class DiscountButton extends Component { static template = "pos_discount.DiscountButton"; diff --git a/addons/pos_restaurant/static/src/app/tip_screen/tip_screen.js b/addons/pos_restaurant/static/src/app/tip_screen/tip_screen.js index 7cf3fa325df..5f99d32fa4e 100644 --- a/addons/pos_restaurant/static/src/app/tip_screen/tip_screen.js +++ b/addons/pos_restaurant/static/src/app/tip_screen/tip_screen.js @@ -26,7 +26,9 @@ export class TipScreen extends Component { }); } get overallAmountStr() { - const tipAmount = parseFloat(this.state.inputTipAmount || "0"); + const tipAmount = this.env.utils.isValidFloat(this.state.inputTipAmount) + ? parseFloat(this.state.inputTipAmount) + : 0; const original = this.env.utils.formatCurrency(this.totalAmount); const tip = this.env.utils.formatCurrency(tipAmount); const overall = this.env.utils.formatCurrency(this.totalAmount + tipAmount); @@ -46,7 +48,9 @@ export class TipScreen extends Component { ]; } async validateTip() { - const amount = parseFloat(this.state.inputTipAmount) || 0; + const amount = this.env.utils.isValidFloat(this.state.inputTipAmount) + ? parseFloat(this.state.inputTipAmount) + : 0; const order = this.pos.get_order(); const serverId = this.pos.validated_orders_name_server_id_map[order.name]; diff --git a/addons/pos_restaurant/static/src/overrides/components/ticket_screen/ticket_screen.js b/addons/pos_restaurant/static/src/overrides/components/ticket_screen/ticket_screen.js index 73906630fc5..ecfc1f35217 100644 --- a/addons/pos_restaurant/static/src/overrides/components/ticket_screen/ticket_screen.js +++ b/addons/pos_restaurant/static/src/overrides/components/ticket_screen/ticket_screen.js @@ -60,7 +60,9 @@ patch(TicketScreen.prototype, { async settleTips() { // set tip in each order for (const order of this.getFilteredOrderList()) { - const tipAmount = parseFloat(order.uiState.TipScreen.inputTipAmount || "0"); + const tipAmount = this.env.utils.isValidFloat(order.uiState.TipScreen.inputTipAmount) + ? parseFloat(order.uiState.TipScreen.inputTipAmount) + : 0; const serverId = this.pos.validated_orders_name_server_id_map[order.name]; if (!serverId) { console.warn( @@ -143,7 +145,11 @@ export class TipCell extends Component { useAutofocus(); } get tipAmountStr() { - return this.env.utils.formatCurrency(parseFloat(this.orderUiState.inputTipAmount || "0")); + return this.env.utils.formatCurrency( + this.env.utils.isValidFloat(this.orderUiState.inputTipAmount) + ? parseFloat(this.orderUiState.inputTipAmount) + : 0 + ); } onBlur() { this.state.isEditing = false;