[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) <jcb@odoo.com>
This commit is contained in:
Adrien Guilliams (adgu)
2023-11-30 07:37:08 +00:00
parent 2b7f88004d
commit f94d14833c
6 changed files with 21 additions and 6 deletions
@@ -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,
});
@@ -54,4 +54,7 @@ export class MoneyDetailsPopup extends AbstractAwaitablePopup {
this.pos.logEmployeeMessage(this.props.action, "ACTION_CANCELLED");
}
}
_parseFloat(value) {
return parseFloat(value);
}
}
@@ -11,7 +11,7 @@
<div t-foreach="bills" t-as="moneyValue" t-key="moneyValue" class="d-flex align-items-center justify-content-center my-1 ">
<NumericInput class="'mx-2 w-50'" tModel="[state.moneyDetails, moneyValue]" min="0"/>
<label class="oe_link_icon w-25 text-end">
<span class="mx-1" t-esc="env.utils.formatStrCurrency(moneyValue)"/>
<span class="mx-1" t-esc="env.utils.formatCurrency(_parseFloat(moneyValue))"/>
</label>
</div>
</div>
@@ -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";
@@ -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];
@@ -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;