From 17882e3262ef708aa043915ddc5a1d9f17c877ec Mon Sep 17 00:00:00 2001 From: Joseph Caburnay Date: Fri, 28 Apr 2023 14:21:21 +0000 Subject: [PATCH] [REF] point_of_sale: define formatProductQty in the contextual_utils_service closes odoo/odoo#120317 Related: odoo/enterprise#40608 Signed-off-by: Samuel Degueldre --- .../static/src/app/contextual_utils_service.js | 8 +++++++- .../src/js/Screens/TicketScreen/OrderlineDetails.js | 4 ++-- addons/point_of_sale/static/src/js/models.js | 8 +------- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/addons/point_of_sale/static/src/app/contextual_utils_service.js b/addons/point_of_sale/static/src/app/contextual_utils_service.js index 27988d6c06f..c2649e2fcc4 100644 --- a/addons/point_of_sale/static/src/app/contextual_utils_service.js +++ b/addons/point_of_sale/static/src/app/contextual_utils_service.js @@ -1,6 +1,6 @@ /** @odoo-module */ -import { formatMonetary } from "@web/views/fields/formatters"; +import { formatMonetary, formatFloat } from "@web/views/fields/formatters"; import { roundDecimals } from "@web/core/utils/numbers"; import { registry } from "@web/core/registry"; @@ -12,6 +12,11 @@ export const contextualUtilsService = { dependencies: ["pos"], start(env, { pos }) { const currency = pos.globalState.currency; + const productUoMDecimals = pos.globalState.dp["Product Unit of Measure"]; + + const formatProductQty = (qty) => { + return formatFloat(qty, { digits: [true, productUoMDecimals] }); + }; const formatCurrency = (value, hasSymbol = true) => { return formatMonetary(value, { @@ -27,6 +32,7 @@ export const contextualUtilsService = { env.utils = { formatCurrency, roundCurrency, + formatProductQty, }; }, }; diff --git a/addons/point_of_sale/static/src/js/Screens/TicketScreen/OrderlineDetails.js b/addons/point_of_sale/static/src/js/Screens/TicketScreen/OrderlineDetails.js index b84675bfcfa..036302cd65b 100644 --- a/addons/point_of_sale/static/src/js/Screens/TicketScreen/OrderlineDetails.js +++ b/addons/point_of_sale/static/src/js/Screens/TicketScreen/OrderlineDetails.js @@ -57,7 +57,7 @@ export class OrderlineDetails extends Component { return !this.env.pos.isProductQtyZero(this.props.line.refunded_qty); } getFormattedRefundedQty() { - return this.env.pos.formatProductQty(this.props.line.refunded_qty); + return this.env.utils.formatProductQty(this.props.line.refunded_qty); } hasToRefundQty() { const toRefundDetail = this.getToRefundDetail(); @@ -65,7 +65,7 @@ export class OrderlineDetails extends Component { } getFormattedToRefundQty() { const toRefundDetail = this.getToRefundDetail(); - return this.env.pos.formatProductQty(toRefundDetail && toRefundDetail.qty); + return this.env.utils.formatProductQty(toRefundDetail && toRefundDetail.qty); } getRefundingMessage() { return sprintf(this.env._t("Refunding %s in "), this.getFormattedToRefundQty()); diff --git a/addons/point_of_sale/static/src/js/models.js b/addons/point_of_sale/static/src/js/models.js index 8b5425a7d4c..f45c64a8072 100644 --- a/addons/point_of_sale/static/src/js/models.js +++ b/addons/point_of_sale/static/src/js/models.js @@ -1491,12 +1491,6 @@ export class PosGlobalState extends PosModel { return floatIsZero(qty, this.dp["Product Unit of Measure"]); } - formatProductQty(qty) { - return formatFloat(qty, { - digits: [true, this.dp["Product Unit of Measure"]], - }); - } - disallowLineQuantityChange() { return false; } @@ -2019,7 +2013,7 @@ export class Orderline extends PosModel { _t( "The requested quantity to be refunded is higher than the refundable quantity of %s." ), - this.pos.formatProductQty(maxQtyToRefund) + this.pos.env.utils.formatProductQty(maxQtyToRefund) ), }); return false;