diff --git a/addons/l10n_ae_pos/static/src/xml/Screens/ReceiptScreen/OrderReceipt.xml b/addons/l10n_ae_pos/static/src/xml/Screens/ReceiptScreen/OrderReceipt.xml index 88913107b57..b18b043abac 100644 --- a/addons/l10n_ae_pos/static/src/xml/Screens/ReceiptScreen/OrderReceipt.xml +++ b/addons/l10n_ae_pos/static/src/xml/Screens/ReceiptScreen/OrderReceipt.xml @@ -5,7 +5,7 @@
VAT Total Taxes - +
diff --git a/addons/l10n_fr_pos_cert/static/src/xml/OrderReceipt.xml b/addons/l10n_fr_pos_cert/static/src/xml/OrderReceipt.xml index 312c06d75a6..2051b031946 100644 --- a/addons/l10n_fr_pos_cert/static/src/xml/OrderReceipt.xml +++ b/addons/l10n_fr_pos_cert/static/src/xml/OrderReceipt.xml @@ -16,7 +16,7 @@ Old unit price: - / Units + / Units diff --git a/addons/l10n_fr_pos_cert/static/src/xml/Orderline.xml b/addons/l10n_fr_pos_cert/static/src/xml/Orderline.xml index 36975221f5f..49420409f77 100644 --- a/addons/l10n_fr_pos_cert/static/src/xml/Orderline.xml +++ b/addons/l10n_fr_pos_cert/static/src/xml/Orderline.xml @@ -8,7 +8,7 @@ Old unit price: - / Units + / Units diff --git a/addons/l10n_gcc_pos/static/src/xml/OrderReceipt.xml b/addons/l10n_gcc_pos/static/src/xml/OrderReceipt.xml index 04a417eab2a..88fa1fbc571 100644 --- a/addons/l10n_gcc_pos/static/src/xml/OrderReceipt.xml +++ b/addons/l10n_gcc_pos/static/src/xml/OrderReceipt.xml @@ -24,73 +24,73 @@ - + !receipt.is_gcc_country - +
Subtotal / الإجمالي الفرعي - +
- + !receipt.is_gcc_country - +
TOTAL / الإجمالي - +
- + !receipt.is_gcc_country - +
Rounding / التقريب - +
- + !receipt.is_gcc_country - +
To Pay / للسداد - +
- + !receipt.is_gcc_country - +
CHANGE / الباقي - +
- + !receipt.is_gcc_country - +
Discounts / الخصومات - +
- + !receipt.is_gcc_country - +
Total Taxes / إجمالي الضرائب - +
@@ -102,9 +102,9 @@
-
Taxes / الضرائب
: +
Taxes / الضرائب
:
- +
@@ -117,13 +117,13 @@ x - +
-
Taxes / الضرائب
: +
Taxes / الضرائب
:
- +
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 new file mode 100644 index 00000000000..71e5074c361 --- /dev/null +++ b/addons/point_of_sale/static/src/app/contextual_utils_service.js @@ -0,0 +1,28 @@ +/** @odoo-module */ + +import { formatMonetary } from "@web/views/fields/formatters"; +import { registry } from "@web/core/registry"; + +/** + * This service introduces `utils` namespace in the `env` which can contain + * functions that are parameterized by the data in `pos` service. + */ +export const contextualUtilsService = { + dependencies: ["pos"], + start(env, { pos }) { + const currency = pos.globalState.currency; + + const formatCurrency = (value, hasSymbol = true) => { + return formatMonetary(value, { + currencyId: currency.id, + noSymbol: !hasSymbol, + }); + }; + + env.utils = { + formatCurrency, + }; + }, +}; + +registry.category("services").add("contextual_utils_service", contextualUtilsService); 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 137b0173959..f2ba6e8fb60 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 @@ -45,7 +45,7 @@ export class CashMovePopup extends AbstractAwaitablePopup { this.state.errorMessage = this.env._t("Insert a positive amount"); return; } - const formattedAmount = this.pos.globalState.format_currency(amount); + const formattedAmount = this.env.utils.formatCurrency(amount); if (!amount) { this.notification.add( sprintf(_t("Cash in/out of %s is ignored."), formattedAmount), diff --git a/addons/point_of_sale/static/src/js/ChromeWidgets/SaleDetailsButton.js b/addons/point_of_sale/static/src/js/ChromeWidgets/SaleDetailsButton.js index 07ec8fe58f3..fee2b50d0b6 100644 --- a/addons/point_of_sale/static/src/js/ChromeWidgets/SaleDetailsButton.js +++ b/addons/point_of_sale/static/src/js/ChromeWidgets/SaleDetailsButton.js @@ -29,6 +29,7 @@ export class SaleDetailsButton extends Component { Object.assign({}, saleDetails, { date: new Date().toLocaleString(), pos: this.env.pos, + formatCurrency: this.env.utils.formatCurrency, }) ); const { successful, message } = await this.hardwareProxy.printer.printReceipt(report); diff --git a/addons/point_of_sale/static/src/js/Misc/MobileOrderWidget.js b/addons/point_of_sale/static/src/js/Misc/MobileOrderWidget.js index c4f08dbfc62..38d617b8d67 100644 --- a/addons/point_of_sale/static/src/js/Misc/MobileOrderWidget.js +++ b/addons/point_of_sale/static/src/js/Misc/MobileOrderWidget.js @@ -15,7 +15,7 @@ export class MobileOrderWidget extends Component { } get total() { const _total = this.order ? this.order.get_total_with_tax() : 0; - return this.env.pos.format_currency(_total); + return this.env.utils.formatCurrency(_total); } get items_number() { return this.order 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 2873844aba1..6f6fbf1bde7 100644 --- a/addons/point_of_sale/static/src/js/Popups/ClosePosPopup.js +++ b/addons/point_of_sale/static/src/js/Popups/ClosePosPopup.js @@ -57,7 +57,7 @@ export class ClosePosPopup extends AbstractAwaitablePopup { "The maximum difference allowed is %s.\n\ Please contact your manager to accept the closing difference." ), - this.pos.globalState.format_currency(this.amountAuthorizedDiff) + this.env.utils.formatCurrency(this.amountAuthorizedDiff) ), confirmText: this.env._t("OK"), }); @@ -80,7 +80,7 @@ export class ClosePosPopup extends AbstractAwaitablePopup { const { total, moneyDetailsNotes, moneyDetails } = payload; this.state.payments[this.defaultCashDetails.id].counted = total; this.state.payments[this.defaultCashDetails.id].difference = - this.pos.globalState.round_decimals_currency( + this.env.utils.roundCurrency( this.state.payments[[this.defaultCashDetails.id]].counted - this.defaultCashDetails.amount ); @@ -106,7 +106,7 @@ export class ClosePosPopup extends AbstractAwaitablePopup { } else { expectedAmount = this.otherPaymentMethods.find((pm) => paymentId === pm.id).amount; } - this.state.payments[paymentId].difference = this.pos.globalState.round_decimals_currency( + this.state.payments[paymentId].difference = this.env.utils.roundCurrency( this.state.payments[paymentId].counted - expectedAmount ); } diff --git a/addons/point_of_sale/static/src/js/Popups/MoneyDetailsPopup.js b/addons/point_of_sale/static/src/js/Popups/MoneyDetailsPopup.js index b1e37e2f655..9708e5b5df6 100644 --- a/addons/point_of_sale/static/src/js/Popups/MoneyDetailsPopup.js +++ b/addons/point_of_sale/static/src/js/Popups/MoneyDetailsPopup.js @@ -45,7 +45,7 @@ export class MoneyDetailsPopup extends AbstractAwaitablePopup { if (this.state.moneyDetails[bill.value]) { moneyDetailsNotes += ` - ${ this.state.moneyDetails[bill.value] - } x ${this.pos.globalState.format_currency(bill.value)}\n`; + } x ${this.env.utils.formatCurrency(bill.value)}\n`; } }); return { diff --git a/addons/point_of_sale/static/src/js/Screens/PaymentScreen/PaymentScreen.js b/addons/point_of_sale/static/src/js/Screens/PaymentScreen/PaymentScreen.js index 5631e38c3b8..2786d2ca0a6 100644 --- a/addons/point_of_sale/static/src/js/Screens/PaymentScreen/PaymentScreen.js +++ b/addons/point_of_sale/static/src/js/Screens/PaymentScreen/PaymentScreen.js @@ -430,11 +430,11 @@ export class PaymentScreen extends Component { body: this.env._t("Are you sure that the customer wants to pay") + " " + - this.env.pos.format_currency(this.currentOrder.get_total_paid()) + + this.env.utils.formatCurrency(this.currentOrder.get_total_paid()) + " " + this.env._t("for an order of") + " " + - this.env.pos.format_currency(this.currentOrder.get_total_with_tax()) + + this.env.utils.formatCurrency(this.currentOrder.get_total_with_tax()) + " " + this.env._t('? Clicking "Confirm" will validate the payment.'), }) diff --git a/addons/point_of_sale/static/src/js/Screens/PaymentScreen/PaymentScreenPaymentLines.js b/addons/point_of_sale/static/src/js/Screens/PaymentScreen/PaymentScreenPaymentLines.js index 8f1b6274ea2..dfd0e867514 100644 --- a/addons/point_of_sale/static/src/js/Screens/PaymentScreen/PaymentScreenPaymentLines.js +++ b/addons/point_of_sale/static/src/js/Screens/PaymentScreen/PaymentScreenPaymentLines.js @@ -6,7 +6,7 @@ export class PaymentScreenPaymentLines extends Component { static template = "PaymentScreenPaymentLines"; formatLineAmount(paymentline) { - return this.env.pos.format_currency_no_symbol(paymentline.get_amount()); + return this.env.utils.formatCurrency(paymentline.get_amount(), false); } selectedLineClass(line) { return { "payment-terminal": line.get_payment_status() }; diff --git a/addons/point_of_sale/static/src/js/Screens/PaymentScreen/PaymentScreenStatus.js b/addons/point_of_sale/static/src/js/Screens/PaymentScreen/PaymentScreenStatus.js index cf604f7c331..b81754acac0 100644 --- a/addons/point_of_sale/static/src/js/Screens/PaymentScreen/PaymentScreenStatus.js +++ b/addons/point_of_sale/static/src/js/Screens/PaymentScreen/PaymentScreenStatus.js @@ -6,15 +6,15 @@ export class PaymentScreenStatus extends Component { static template = "PaymentScreenStatus"; get changeText() { - return this.env.pos.format_currency(this.props.order.get_change()); + return this.env.utils.formatCurrency(this.props.order.get_change()); } get totalDueText() { - return this.env.pos.format_currency( + return this.env.utils.formatCurrency( this.props.order.get_total_with_tax() + this.props.order.get_rounding_applied() ); } get remainingText() { - return this.env.pos.format_currency( + return this.env.utils.formatCurrency( this.props.order.get_due() > 0 ? this.props.order.get_due() : 0 ); } diff --git a/addons/point_of_sale/static/src/js/Screens/ProductScreen/OrderSummary.js b/addons/point_of_sale/static/src/js/Screens/ProductScreen/OrderSummary.js index 4297fb16677..dbf5a7f2011 100644 --- a/addons/point_of_sale/static/src/js/Screens/ProductScreen/OrderSummary.js +++ b/addons/point_of_sale/static/src/js/Screens/ProductScreen/OrderSummary.js @@ -7,7 +7,7 @@ export class OrderSummary extends Component { static template = "OrderSummary"; getTotal() { - return this.env.pos.format_currency(this.props.order.get_total_with_tax()); + return this.env.utils.formatCurrency(this.props.order.get_total_with_tax()); } getTax() { const total = this.props.order.get_total_with_tax(); @@ -15,7 +15,7 @@ export class OrderSummary extends Component { const taxAmount = total - totalWithoutTax; return { hasTax: !floatIsZero(taxAmount, this.env.pos.currency.decimal_places), - displayAmount: this.env.pos.format_currency(taxAmount), + displayAmount: this.env.utils.formatCurrency(taxAmount), }; } } diff --git a/addons/point_of_sale/static/src/js/Screens/ProductScreen/ProductItem.js b/addons/point_of_sale/static/src/js/Screens/ProductScreen/ProductItem.js index a3ca2c6f67d..eefccbc7748 100644 --- a/addons/point_of_sale/static/src/js/Screens/ProductScreen/ProductItem.js +++ b/addons/point_of_sale/static/src/js/Screens/ProductScreen/ProductItem.js @@ -32,9 +32,8 @@ export class ProductItem extends Component { return this.env.pos.default_pricelist; } get price() { - const formattedUnitPrice = this.env.pos.format_currency( - this.props.product.get_display_price(this.pricelist, 1), - "Product Price" + const formattedUnitPrice = this.env.utils.formatCurrency( + this.props.product.get_display_price(this.pricelist, 1) ); if (this.props.product.to_weight) { return `${formattedUnitPrice}/${ diff --git a/addons/point_of_sale/static/src/js/Screens/ReceiptScreen/ReceiptScreen.js b/addons/point_of_sale/static/src/js/Screens/ReceiptScreen/ReceiptScreen.js index f8f916a2f34..672180e42f6 100644 --- a/addons/point_of_sale/static/src/js/Screens/ReceiptScreen/ReceiptScreen.js +++ b/addons/point_of_sale/static/src/js/Screens/ReceiptScreen/ReceiptScreen.js @@ -98,11 +98,11 @@ export class ReceiptScreen extends AbstractReceiptScreen { .get_orderlines() .find((line) => tip_product_id && line.product.id === tip_product_id); const tipAmount = tipLine ? tipLine.get_all_prices().priceWithTax : 0; - const orderAmountStr = this.env.pos.format_currency(orderTotalAmount - tipAmount); + const orderAmountStr = this.env.utils.formatCurrency(orderTotalAmount - tipAmount); if (!tipAmount) { return orderAmountStr; } - const tipAmountStr = this.env.pos.format_currency(tipAmount); + const tipAmountStr = this.env.utils.formatCurrency(tipAmount); return `${orderAmountStr} + ${tipAmountStr} tip`; } get nextScreen() { diff --git a/addons/point_of_sale/static/src/js/Screens/ScaleScreen/ScaleScreen.js b/addons/point_of_sale/static/src/js/Screens/ScaleScreen/ScaleScreen.js index e62a40120b2..368fba28c8c 100644 --- a/addons/point_of_sale/static/src/js/Screens/ScaleScreen/ScaleScreen.js +++ b/addons/point_of_sale/static/src/js/Screens/ScaleScreen/ScaleScreen.js @@ -83,7 +83,7 @@ export class ScaleScreen extends Component { return weightstr; } get computedPriceString() { - return this.env.pos.format_currency(this.productPrice * this.state.weight); + return this.env.utils.formatCurrency(this.productPrice * this.state.weight); } get productPrice() { const product = this.props.product; diff --git a/addons/point_of_sale/static/src/js/Screens/TicketScreen/OrderDetails.js b/addons/point_of_sale/static/src/js/Screens/TicketScreen/OrderDetails.js index 0b81b928cd8..d99a817ae15 100644 --- a/addons/point_of_sale/static/src/js/Screens/TicketScreen/OrderDetails.js +++ b/addons/point_of_sale/static/src/js/Screens/TicketScreen/OrderDetails.js @@ -17,9 +17,9 @@ export class OrderDetails extends Component { return this.order ? this.order.orderlines : []; } get total() { - return this.env.pos.format_currency(this.order ? this.order.get_total_with_tax() : 0); + return this.env.utils.formatCurrency(this.order ? this.order.get_total_with_tax() : 0); } get tax() { - return this.env.pos.format_currency(this.order ? this.order.get_total_tax() : 0); + return this.env.utils.formatCurrency(this.order ? this.order.get_total_tax() : 0); } } 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 95fa217ce2e..b84675bfcfa 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 @@ -33,13 +33,13 @@ export class OrderlineDetails extends Component { return this.line.productName; } get totalPrice() { - return this.env.pos.format_currency(this.line.totalPrice); + return this.env.utils.formatCurrency(this.line.totalPrice); } get quantity() { return this.line.quantity; } get unitPrice() { - return this.env.pos.format_currency(this.line.unitPrice); + return this.env.utils.formatCurrency(this.line.unitPrice); } get unit() { return this.line.unit; diff --git a/addons/point_of_sale/static/src/js/Screens/TicketScreen/TicketScreen.js b/addons/point_of_sale/static/src/js/Screens/TicketScreen/TicketScreen.js index 88c4fe290dd..eb2142a149b 100644 --- a/addons/point_of_sale/static/src/js/Screens/TicketScreen/TicketScreen.js +++ b/addons/point_of_sale/static/src/js/Screens/TicketScreen/TicketScreen.js @@ -334,7 +334,7 @@ export class TicketScreen extends IndependentToOrderScreen { return moment(order.validation_date).format("YYYY-MM-DD hh:mm A"); } getTotal(order) { - return this.env.pos.format_currency(order.get_total_with_tax()); + return this.env.utils.formatCurrency(order.get_total_with_tax()); } getPartner(order) { return order.get_partner_name(); diff --git a/addons/point_of_sale/static/src/js/models.js b/addons/point_of_sale/static/src/js/models.js index eed913f9863..a3ba8834436 100644 --- a/addons/point_of_sale/static/src/js/models.js +++ b/addons/point_of_sale/static/src/js/models.js @@ -837,14 +837,14 @@ export class PosGlobalState extends PosModel { const orderCost = order.get_total_cost(); const orderMargin = orderPriceWithoutTax - orderCost; - const costCurrency = this.format_currency(product.standard_price); - const marginCurrency = this.format_currency(margin); + const costCurrency = this.env.utils.formatCurrency(product.standard_price); + const marginCurrency = this.env.utils.formatCurrency(margin); const marginPercent = priceWithoutTax ? Math.round((margin / priceWithoutTax) * 10000) / 100 : 0; - const orderPriceWithoutTaxCurrency = this.format_currency(orderPriceWithoutTax); - const orderCostCurrency = this.format_currency(orderCost); - const orderMarginCurrency = this.format_currency(orderMargin); + const orderPriceWithoutTaxCurrency = this.env.utils.formatCurrency(orderPriceWithoutTax); + const orderCostCurrency = this.env.utils.formatCurrency(orderCost); + const orderMarginCurrency = this.env.utils.formatCurrency(orderMargin); const orderMarginPercent = orderPriceWithoutTax ? Math.round((orderMargin / orderPriceWithoutTax) * 10000) / 100 : 0; @@ -958,6 +958,7 @@ export class PosGlobalState extends PosModel { return renderToString("CustomerFacingDisplayOrder", { pos: this, + formatCurrency: this.env.utils.formatCurrency, origin: window.location.origin, order, productImages, @@ -1496,36 +1497,6 @@ export class PosGlobalState extends PosModel { }); } - format_currency(amount, precision) { - amount = this.format_currency_no_symbol(amount, precision, this.currency); - - if (this.currency.position === "after") { - return amount + " " + (this.currency.symbol || ""); - } else { - return (this.currency.symbol || "") + " " + amount; - } - } - - format_currency_no_symbol(amount, precision, currency) { - if (!currency) { - currency = this.currency; - } - var decimals = currency.decimal_places; - - if (precision && this.dp[precision] !== undefined) { - decimals = this.dp[precision]; - } - - if (typeof amount === "number") { - amount = round_di(amount, decimals).toFixed(decimals); - amount = formatFloat(round_di(amount, decimals), { - digits: [69, decimals], - }); - } - - return amount; - } - format_pr(value, precision) { var decimals = precision > 0 ? Math.max(0, Math.ceil(Math.log(1.0 / precision) / Math.log(10))) : 0; @@ -2378,8 +2349,8 @@ export class Orderline extends PosModel { return this.compute_all(product_taxes, lst_price, 1, this.pos.currency.rounding) .total_included; } - var digits = this.pos.dp['Product Price']; - return lst_price.toFixed(digits) + var digits = this.pos.dp["Product Price"]; + return lst_price.toFixed(digits); } get_price_without_tax() { return this.get_all_prices().priceWithoutTax; @@ -3399,7 +3370,9 @@ export class Order extends PosModel { var self = this; this.pricelist = pricelist; - var lines_to_recompute = this.get_orderlines().filter((line) => !(line.price_manually_set || line.price_automatically_set)); + var lines_to_recompute = this.get_orderlines().filter( + (line) => !(line.price_manually_set || line.price_automatically_set) + ); lines_to_recompute.forEach((line) => { line.set_unit_price( line.product.get_price(self.pricelist, line.get_quantity(), line.get_price_extra()) @@ -3650,9 +3623,14 @@ export class Order extends PosModel { return []; } _reduce_total_discount_callback(sum, orderLine) { - sum += (orderLine.get_unit_price() * (orderLine.get_discount()/100) * orderLine.get_quantity()); - if (orderLine.display_discount_policy() === 'without_discount'){ - sum += ((orderLine.get_taxed_lst_unit_price() - orderLine.get_unit_price()) * orderLine.get_quantity()); + sum += + orderLine.get_unit_price() * + (orderLine.get_discount() / 100) * + orderLine.get_quantity(); + if (orderLine.display_discount_policy() === "without_discount") { + sum += + (orderLine.get_taxed_lst_unit_price() - orderLine.get_unit_price()) * + orderLine.get_quantity(); } return sum; } diff --git a/addons/point_of_sale/static/src/xml/CustomerFacingDisplay/CustomerFacingDisplayOrder.xml b/addons/point_of_sale/static/src/xml/CustomerFacingDisplay/CustomerFacingDisplayOrder.xml index 518c8f87226..a1d93f22ffa 100644 --- a/addons/point_of_sale/static/src/xml/CustomerFacingDisplay/CustomerFacingDisplayOrder.xml +++ b/addons/point_of_sale/static/src/xml/CustomerFacingDisplay/CustomerFacingDisplayOrder.xml @@ -33,7 +33,7 @@ TOTAL
- +
@@ -63,7 +63,7 @@
-
+
@@ -78,7 +78,7 @@ :
- +
@@ -87,7 +87,7 @@ Change
- +
diff --git a/addons/point_of_sale/static/src/xml/Popups/ClosePosPopup.xml b/addons/point_of_sale/static/src/xml/Popups/ClosePosPopup.xml index 3c47004a2ac..b971ef245f5 100644 --- a/addons/point_of_sale/static/src/xml/Popups/ClosePosPopup.xml +++ b/addons/point_of_sale/static/src/xml/Popups/ClosePosPopup.xml @@ -7,7 +7,7 @@
Closing Session
Total orders: - +
@@ -25,20 +25,20 @@ - +
- + Opening - + @@ -47,7 +47,7 @@ - + @@ -56,17 +56,17 @@ Payments in - + - + - + diff --git a/addons/point_of_sale/static/src/xml/Popups/MoneyDetailsPopup.xml b/addons/point_of_sale/static/src/xml/Popups/MoneyDetailsPopup.xml index 8a8914b4a24..8e61204f6f6 100644 --- a/addons/point_of_sale/static/src/xml/Popups/MoneyDetailsPopup.xml +++ b/addons/point_of_sale/static/src/xml/Popups/MoneyDetailsPopup.xml @@ -18,7 +18,7 @@
Total - +