[REF] point_of_sale,*: redefine format_currency{_no_symbol} using web's formatMonetary

*: l10n_ae_pos,l10n_fr_pos_cert,l10n_gcc_pos,pos_loyalty,pos_restaurant,
   pos_sale,pos_sale_product_configurator

This commit is the start of a series of changes in the definitions of formatters
and rounders used in pos. We are introducing a new service called
`contextual_utils_service` that loads when the `pos` service is ready making
sure the currency is loaded. In this service, we define `formatCurrency`
(potentially others) which is the replacement to `format_currency{_no_symbol}`.
Also, instead of defining our own formatter, we are depending on web's
`formatMonetary`.

In this commit, we are replacing all uses of `format_currency{_no_symbol}` with
`formatCurrency` that's based on web's `formatMonetary`.

Part-of: odoo/odoo#120317
This commit is contained in:
Joseph Caburnay
2023-05-08 15:18:30 +02:00
parent 02dad87ba6
commit 5d951d91bb
46 changed files with 181 additions and 173 deletions
@@ -5,7 +5,7 @@
<div id='post_receipt_taxes_container'> <div id='post_receipt_taxes_container'>
<t t-if="env.pos.company.country.code == 'AE'">VAT</t> <t t-if="env.pos.company.country.code == 'AE'">VAT</t>
<t t-else="">Total Taxes</t> <t t-else="">Total Taxes</t>
<span t-esc="env.pos.format_currency(receipt.total_tax)" class="pos-receipt-right-align"/> <span t-esc="env.utils.formatCurrency(receipt.total_tax)" class="pos-receipt-right-align"/>
</div> </div>
</xpath> </xpath>
</t> </t>
@@ -16,7 +16,7 @@
Old unit price: Old unit price:
<span class="oldPrice"> <span class="oldPrice">
<s> <s>
<t t-out="env.pos.format_currency(line.taxed_lst_unit_price, 'Product Price')" /> / Units <t t-out="env.utils.formatCurrency(line.taxed_lst_unit_price)" /> / Units
</s> </s>
</span> </span>
</div> </div>
@@ -8,7 +8,7 @@
Old unit price: Old unit price:
<span class="oldPrice"> <span class="oldPrice">
<s> <s>
<t t-out="env.pos.format_currency(props.line.get_taxed_lst_unit_price(),'Product Price')" /> / Units <t t-out="env.utils.formatCurrency(props.line.get_taxed_lst_unit_price())" /> / Units
</s> </s>
</span> </span>
</li> </li>
@@ -24,73 +24,73 @@
</div> </div>
</xpath> </xpath>
<xpath expr="//span[@t-esc='env.pos.format_currency(receipt.subtotal)']/.." position="attributes"> <xpath expr="//span[@t-esc='env.utils.formatCurrency(receipt.subtotal)']/.." position="attributes">
<attribute name="t-if">!receipt.is_gcc_country</attribute> <attribute name="t-if">!receipt.is_gcc_country</attribute>
</xpath> </xpath>
<xpath expr="//span[@t-esc='env.pos.format_currency(receipt.subtotal)']/.." position="after"> <xpath expr="//span[@t-esc='env.utils.formatCurrency(receipt.subtotal)']/.." position="after">
<div t-if="receipt.is_gcc_country" t-translation="off"> <div t-if="receipt.is_gcc_country" t-translation="off">
Subtotal / الإجمالي الفرعي Subtotal / الإجمالي الفرعي
<span t-esc="env.pos.format_currency(receipt.subtotal)" class="pos-receipt-right-align"/> <span t-esc="env.utils.formatCurrency(receipt.subtotal)" class="pos-receipt-right-align"/>
</div> </div>
</xpath> </xpath>
<xpath expr="//span[@t-esc='env.pos.format_currency(receipt.total_with_tax)']/.." position="attributes"> <xpath expr="//span[@t-esc='env.utils.formatCurrency(receipt.total_with_tax)']/.." position="attributes">
<attribute name="t-if">!receipt.is_gcc_country</attribute> <attribute name="t-if">!receipt.is_gcc_country</attribute>
</xpath> </xpath>
<xpath expr="//span[@t-esc='env.pos.format_currency(receipt.total_with_tax)']/.." position="after"> <xpath expr="//span[@t-esc='env.utils.formatCurrency(receipt.total_with_tax)']/.." position="after">
<div t-if="receipt.is_gcc_country" class="pos-receipt-amount pos-receipt-amount-arabic" t-translation="off"> <div t-if="receipt.is_gcc_country" class="pos-receipt-amount pos-receipt-amount-arabic" t-translation="off">
TOTAL / الإجمالي TOTAL / الإجمالي
<span t-esc="env.pos.format_currency(receipt.total_with_tax)" class="pos-receipt-right-align"/> <span t-esc="env.utils.formatCurrency(receipt.total_with_tax)" class="pos-receipt-right-align"/>
</div> </div>
</xpath> </xpath>
<xpath expr="//span[@t-esc='env.pos.format_currency(receipt.rounding_applied)']/.." position="attributes"> <xpath expr="//span[@t-esc='env.utils.formatCurrency(receipt.rounding_applied)']/.." position="attributes">
<attribute name="t-if">!receipt.is_gcc_country</attribute> <attribute name="t-if">!receipt.is_gcc_country</attribute>
</xpath> </xpath>
<xpath expr="//span[@t-esc='env.pos.format_currency(receipt.rounding_applied)']/.." position="after"> <xpath expr="//span[@t-esc='env.utils.formatCurrency(receipt.rounding_applied)']/.." position="after">
<div t-if="receipt.is_gcc_country" class="pos-receipt-amount pos-receipt-amount-arabic" t-translation="off"> <div t-if="receipt.is_gcc_country" class="pos-receipt-amount pos-receipt-amount-arabic" t-translation="off">
Rounding / التقريب Rounding / التقريب
<span t-esc="env.pos.format_currency(receipt.rounding_applied)" class="pos-receipt-right-align"/> <span t-esc="env.utils.formatCurrency(receipt.rounding_applied)" class="pos-receipt-right-align"/>
</div> </div>
</xpath> </xpath>
<xpath expr="//span[@t-esc='env.pos.format_currency(receipt.total_rounded)']/.." position="attributes"> <xpath expr="//span[@t-esc='env.utils.formatCurrency(receipt.total_rounded)']/.." position="attributes">
<attribute name="t-if">!receipt.is_gcc_country</attribute> <attribute name="t-if">!receipt.is_gcc_country</attribute>
</xpath> </xpath>
<xpath expr="//span[@t-esc='env.pos.format_currency(receipt.total_rounded)']/.." position="after"> <xpath expr="//span[@t-esc='env.utils.formatCurrency(receipt.total_rounded)']/.." position="after">
<div t-if="receipt.is_gcc_country" class="pos-receipt-amount pos-receipt-amount-arabic" t-translation="off"> <div t-if="receipt.is_gcc_country" class="pos-receipt-amount pos-receipt-amount-arabic" t-translation="off">
To Pay / للسداد To Pay / للسداد
<span t-esc="env.pos.format_currency(receipt.total_rounded)" class="pos-receipt-right-align"/> <span t-esc="env.utils.formatCurrency(receipt.total_rounded)" class="pos-receipt-right-align"/>
</div> </div>
</xpath> </xpath>
<xpath expr="//span[@t-esc='env.pos.format_currency(receipt.change)']/.." position="attributes"> <xpath expr="//span[@t-esc='env.utils.formatCurrency(receipt.change)']/.." position="attributes">
<attribute name="t-if">!receipt.is_gcc_country</attribute> <attribute name="t-if">!receipt.is_gcc_country</attribute>
</xpath> </xpath>
<xpath expr="//span[@t-esc='env.pos.format_currency(receipt.change)']/.." position="after"> <xpath expr="//span[@t-esc='env.utils.formatCurrency(receipt.change)']/.." position="after">
<div t-if="receipt.is_gcc_country" class="pos-receipt-amount receipt-change pos-receipt-amount-arabic" t-translation="off"> <div t-if="receipt.is_gcc_country" class="pos-receipt-amount receipt-change pos-receipt-amount-arabic" t-translation="off">
CHANGE / الباقي CHANGE / الباقي
<span t-esc="env.pos.format_currency(receipt.change)" class="pos-receipt-right-align"/> <span t-esc="env.utils.formatCurrency(receipt.change)" class="pos-receipt-right-align"/>
</div> </div>
</xpath> </xpath>
<xpath expr="//span[@t-esc='env.pos.format_currency(receipt.total_discount)']/.." position="attributes"> <xpath expr="//span[@t-esc='env.utils.formatCurrency(receipt.total_discount)']/.." position="attributes">
<attribute name="t-if">!receipt.is_gcc_country</attribute> <attribute name="t-if">!receipt.is_gcc_country</attribute>
</xpath> </xpath>
<xpath expr="//span[@t-esc='env.pos.format_currency(receipt.total_discount)']/.." position="after"> <xpath expr="//span[@t-esc='env.utils.formatCurrency(receipt.total_discount)']/.." position="after">
<div t-if="receipt.is_gcc_country" t-translation="off"> <div t-if="receipt.is_gcc_country" t-translation="off">
Discounts / الخصومات Discounts / الخصومات
<span t-esc="env.pos.format_currency(receipt.total_discount)" class="pos-receipt-right-align"/> <span t-esc="env.utils.formatCurrency(receipt.total_discount)" class="pos-receipt-right-align"/>
</div> </div>
</xpath> </xpath>
<xpath expr="//span[@t-esc='env.pos.format_currency(receipt.total_tax)']/.." position="attributes"> <xpath expr="//span[@t-esc='env.utils.formatCurrency(receipt.total_tax)']/.." position="attributes">
<attribute name="t-if">!receipt.is_gcc_country</attribute> <attribute name="t-if">!receipt.is_gcc_country</attribute>
</xpath> </xpath>
<xpath expr="//span[@t-esc='env.pos.format_currency(receipt.total_tax)']/.." position="after"> <xpath expr="//span[@t-esc='env.utils.formatCurrency(receipt.total_tax)']/.." position="after">
<div t-if="receipt.is_gcc_country" t-translation="off"> <div t-if="receipt.is_gcc_country" t-translation="off">
Total Taxes / إجمالي الضرائب Total Taxes / إجمالي الضرائب
<span t-esc="env.pos.format_currency(receipt.total_tax)" class="pos-receipt-right-align"/> <span t-esc="env.utils.formatCurrency(receipt.total_tax)" class="pos-receipt-right-align"/>
</div> </div>
</xpath> </xpath>
</t> </t>
@@ -102,9 +102,9 @@
<xpath expr="//t[@t-if='isSimple(line)']/WrappedProductNameLines" position="after"> <xpath expr="//t[@t-if='isSimple(line)']/WrappedProductNameLines" position="after">
<div class="responsive-price" t-if="receipt.is_gcc_country"> <div class="responsive-price" t-if="receipt.is_gcc_country">
<div class="pos-receipt-left-padding" style="display: inline-flex;"> <div class="pos-receipt-left-padding" style="display: inline-flex;">
<div t-translation="off">Taxes / الضرائب</div>:<span t-esc="env.pos.format_currency_no_symbol(line.tax)" style="margin-left: 5px"/> <div t-translation="off">Taxes / الضرائب</div>:<span t-esc="env.utils.formatCurrency(line.tax, false)" style="margin-left: 5px"/>
</div> </div>
<span t-esc="env.pos.format_currency_no_symbol(line.price_display)" class="price_display pos-receipt-right-align"/> <span t-esc="env.utils.formatCurrency(line.price_display, false)" class="price_display pos-receipt-right-align"/>
</div> </div>
</xpath> </xpath>
@@ -117,13 +117,13 @@
<t t-esc="Math.round(line.quantity * Math.pow(10, env.pos.dp['Product Unit of Measure'])) / Math.pow(10, env.pos.dp['Product Unit of Measure'])"/> <t t-esc="Math.round(line.quantity * Math.pow(10, env.pos.dp['Product Unit of Measure'])) / Math.pow(10, env.pos.dp['Product Unit of Measure'])"/>
<t t-if="!line.is_in_unit" t-esc="line.unit_name" /> <t t-if="!line.is_in_unit" t-esc="line.unit_name" />
x x
<t t-esc="env.pos.format_currency_no_symbol(line.price_display_one)" /> <t t-esc="env.utils.formatCurrency(line.price_display_one, false)" />
</div> </div>
<div class="responsive-price"> <div class="responsive-price">
<div class="pos-receipt-left-padding" style="display: inline-flex;"> <div class="pos-receipt-left-padding" style="display: inline-flex;">
<div t-translation="off">Taxes / الضرائب</div>:<span t-esc="env.pos.format_currency_no_symbol(line.tax)" style="margin-left: 5px"/> <div t-translation="off">Taxes / الضرائب</div>:<span t-esc="env.utils.formatCurrency(line.tax, false)" style="margin-left: 5px"/>
</div> </div>
<span t-esc="env.pos.format_currency_no_symbol(line.price_display)" class="price_display pos-receipt-right-align"/> <span t-esc="env.utils.formatCurrency(line.price_display, false)" class="price_display pos-receipt-right-align"/>
</div> </div>
</t> </t>
</xpath> </xpath>
@@ -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);
@@ -45,7 +45,7 @@ export class CashMovePopup extends AbstractAwaitablePopup {
this.state.errorMessage = this.env._t("Insert a positive amount"); this.state.errorMessage = this.env._t("Insert a positive amount");
return; return;
} }
const formattedAmount = this.pos.globalState.format_currency(amount); const formattedAmount = this.env.utils.formatCurrency(amount);
if (!amount) { if (!amount) {
this.notification.add( this.notification.add(
sprintf(_t("Cash in/out of %s is ignored."), formattedAmount), sprintf(_t("Cash in/out of %s is ignored."), formattedAmount),
@@ -29,6 +29,7 @@ export class SaleDetailsButton extends Component {
Object.assign({}, saleDetails, { Object.assign({}, saleDetails, {
date: new Date().toLocaleString(), date: new Date().toLocaleString(),
pos: this.env.pos, pos: this.env.pos,
formatCurrency: this.env.utils.formatCurrency,
}) })
); );
const { successful, message } = await this.hardwareProxy.printer.printReceipt(report); const { successful, message } = await this.hardwareProxy.printer.printReceipt(report);
@@ -15,7 +15,7 @@ export class MobileOrderWidget extends Component {
} }
get total() { get total() {
const _total = this.order ? this.order.get_total_with_tax() : 0; 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() { get items_number() {
return this.order return this.order
@@ -57,7 +57,7 @@ export class ClosePosPopup extends AbstractAwaitablePopup {
"The maximum difference allowed is %s.\n\ "The maximum difference allowed is %s.\n\
Please contact your manager to accept the closing difference." 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"), confirmText: this.env._t("OK"),
}); });
@@ -80,7 +80,7 @@ export class ClosePosPopup extends AbstractAwaitablePopup {
const { total, moneyDetailsNotes, moneyDetails } = payload; const { total, moneyDetailsNotes, moneyDetails } = payload;
this.state.payments[this.defaultCashDetails.id].counted = total; this.state.payments[this.defaultCashDetails.id].counted = total;
this.state.payments[this.defaultCashDetails.id].difference = 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.state.payments[[this.defaultCashDetails.id]].counted -
this.defaultCashDetails.amount this.defaultCashDetails.amount
); );
@@ -106,7 +106,7 @@ export class ClosePosPopup extends AbstractAwaitablePopup {
} else { } else {
expectedAmount = this.otherPaymentMethods.find((pm) => paymentId === pm.id).amount; 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 this.state.payments[paymentId].counted - expectedAmount
); );
} }
@@ -45,7 +45,7 @@ export class MoneyDetailsPopup extends AbstractAwaitablePopup {
if (this.state.moneyDetails[bill.value]) { if (this.state.moneyDetails[bill.value]) {
moneyDetailsNotes += ` - ${ moneyDetailsNotes += ` - ${
this.state.moneyDetails[bill.value] this.state.moneyDetails[bill.value]
} x ${this.pos.globalState.format_currency(bill.value)}\n`; } x ${this.env.utils.formatCurrency(bill.value)}\n`;
} }
}); });
return { return {
@@ -430,11 +430,11 @@ export class PaymentScreen extends Component {
body: body:
this.env._t("Are you sure that the customer wants to pay") + 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._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.'), this.env._t('? Clicking "Confirm" will validate the payment.'),
}) })
@@ -6,7 +6,7 @@ export class PaymentScreenPaymentLines extends Component {
static template = "PaymentScreenPaymentLines"; static template = "PaymentScreenPaymentLines";
formatLineAmount(paymentline) { formatLineAmount(paymentline) {
return this.env.pos.format_currency_no_symbol(paymentline.get_amount()); return this.env.utils.formatCurrency(paymentline.get_amount(), false);
} }
selectedLineClass(line) { selectedLineClass(line) {
return { "payment-terminal": line.get_payment_status() }; return { "payment-terminal": line.get_payment_status() };
@@ -6,15 +6,15 @@ export class PaymentScreenStatus extends Component {
static template = "PaymentScreenStatus"; static template = "PaymentScreenStatus";
get changeText() { 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() { 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() this.props.order.get_total_with_tax() + this.props.order.get_rounding_applied()
); );
} }
get remainingText() { 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 this.props.order.get_due() > 0 ? this.props.order.get_due() : 0
); );
} }
@@ -7,7 +7,7 @@ export class OrderSummary extends Component {
static template = "OrderSummary"; static template = "OrderSummary";
getTotal() { 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() { getTax() {
const total = this.props.order.get_total_with_tax(); const total = this.props.order.get_total_with_tax();
@@ -15,7 +15,7 @@ export class OrderSummary extends Component {
const taxAmount = total - totalWithoutTax; const taxAmount = total - totalWithoutTax;
return { return {
hasTax: !floatIsZero(taxAmount, this.env.pos.currency.decimal_places), hasTax: !floatIsZero(taxAmount, this.env.pos.currency.decimal_places),
displayAmount: this.env.pos.format_currency(taxAmount), displayAmount: this.env.utils.formatCurrency(taxAmount),
}; };
} }
} }
@@ -32,9 +32,8 @@ export class ProductItem extends Component {
return this.env.pos.default_pricelist; return this.env.pos.default_pricelist;
} }
get price() { get price() {
const formattedUnitPrice = this.env.pos.format_currency( const formattedUnitPrice = this.env.utils.formatCurrency(
this.props.product.get_display_price(this.pricelist, 1), this.props.product.get_display_price(this.pricelist, 1)
"Product Price"
); );
if (this.props.product.to_weight) { if (this.props.product.to_weight) {
return `${formattedUnitPrice}/${ return `${formattedUnitPrice}/${
@@ -98,11 +98,11 @@ export class ReceiptScreen extends AbstractReceiptScreen {
.get_orderlines() .get_orderlines()
.find((line) => tip_product_id && line.product.id === tip_product_id); .find((line) => tip_product_id && line.product.id === tip_product_id);
const tipAmount = tipLine ? tipLine.get_all_prices().priceWithTax : 0; 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) { if (!tipAmount) {
return orderAmountStr; return orderAmountStr;
} }
const tipAmountStr = this.env.pos.format_currency(tipAmount); const tipAmountStr = this.env.utils.formatCurrency(tipAmount);
return `${orderAmountStr} + ${tipAmountStr} tip`; return `${orderAmountStr} + ${tipAmountStr} tip`;
} }
get nextScreen() { get nextScreen() {
@@ -83,7 +83,7 @@ export class ScaleScreen extends Component {
return weightstr; return weightstr;
} }
get computedPriceString() { 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() { get productPrice() {
const product = this.props.product; const product = this.props.product;
@@ -17,9 +17,9 @@ export class OrderDetails extends Component {
return this.order ? this.order.orderlines : []; return this.order ? this.order.orderlines : [];
} }
get total() { 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() { 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);
} }
} }
@@ -33,13 +33,13 @@ export class OrderlineDetails extends Component {
return this.line.productName; return this.line.productName;
} }
get totalPrice() { get totalPrice() {
return this.env.pos.format_currency(this.line.totalPrice); return this.env.utils.formatCurrency(this.line.totalPrice);
} }
get quantity() { get quantity() {
return this.line.quantity; return this.line.quantity;
} }
get unitPrice() { get unitPrice() {
return this.env.pos.format_currency(this.line.unitPrice); return this.env.utils.formatCurrency(this.line.unitPrice);
} }
get unit() { get unit() {
return this.line.unit; return this.line.unit;
@@ -334,7 +334,7 @@ export class TicketScreen extends IndependentToOrderScreen {
return moment(order.validation_date).format("YYYY-MM-DD hh:mm A"); return moment(order.validation_date).format("YYYY-MM-DD hh:mm A");
} }
getTotal(order) { 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) { getPartner(order) {
return order.get_partner_name(); return order.get_partner_name();
+19 -41
View File
@@ -837,14 +837,14 @@ export class PosGlobalState extends PosModel {
const orderCost = order.get_total_cost(); const orderCost = order.get_total_cost();
const orderMargin = orderPriceWithoutTax - orderCost; const orderMargin = orderPriceWithoutTax - orderCost;
const costCurrency = this.format_currency(product.standard_price); const costCurrency = this.env.utils.formatCurrency(product.standard_price);
const marginCurrency = this.format_currency(margin); const marginCurrency = this.env.utils.formatCurrency(margin);
const marginPercent = priceWithoutTax const marginPercent = priceWithoutTax
? Math.round((margin / priceWithoutTax) * 10000) / 100 ? Math.round((margin / priceWithoutTax) * 10000) / 100
: 0; : 0;
const orderPriceWithoutTaxCurrency = this.format_currency(orderPriceWithoutTax); const orderPriceWithoutTaxCurrency = this.env.utils.formatCurrency(orderPriceWithoutTax);
const orderCostCurrency = this.format_currency(orderCost); const orderCostCurrency = this.env.utils.formatCurrency(orderCost);
const orderMarginCurrency = this.format_currency(orderMargin); const orderMarginCurrency = this.env.utils.formatCurrency(orderMargin);
const orderMarginPercent = orderPriceWithoutTax const orderMarginPercent = orderPriceWithoutTax
? Math.round((orderMargin / orderPriceWithoutTax) * 10000) / 100 ? Math.round((orderMargin / orderPriceWithoutTax) * 10000) / 100
: 0; : 0;
@@ -958,6 +958,7 @@ export class PosGlobalState extends PosModel {
return renderToString("CustomerFacingDisplayOrder", { return renderToString("CustomerFacingDisplayOrder", {
pos: this, pos: this,
formatCurrency: this.env.utils.formatCurrency,
origin: window.location.origin, origin: window.location.origin,
order, order,
productImages, 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) { format_pr(value, precision) {
var decimals = var decimals =
precision > 0 ? Math.max(0, Math.ceil(Math.log(1.0 / precision) / Math.log(10))) : 0; 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) return this.compute_all(product_taxes, lst_price, 1, this.pos.currency.rounding)
.total_included; .total_included;
} }
var digits = this.pos.dp['Product Price']; var digits = this.pos.dp["Product Price"];
return lst_price.toFixed(digits) return lst_price.toFixed(digits);
} }
get_price_without_tax() { get_price_without_tax() {
return this.get_all_prices().priceWithoutTax; return this.get_all_prices().priceWithoutTax;
@@ -3399,7 +3370,9 @@ export class Order extends PosModel {
var self = this; var self = this;
this.pricelist = pricelist; 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) => { lines_to_recompute.forEach((line) => {
line.set_unit_price( line.set_unit_price(
line.product.get_price(self.pricelist, line.get_quantity(), line.get_price_extra()) line.product.get_price(self.pricelist, line.get_quantity(), line.get_price_extra())
@@ -3650,9 +3623,14 @@ export class Order extends PosModel {
return []; return [];
} }
_reduce_total_discount_callback(sum, orderLine) { _reduce_total_discount_callback(sum, orderLine) {
sum += (orderLine.get_unit_price() * (orderLine.get_discount()/100) * orderLine.get_quantity()); sum +=
if (orderLine.display_discount_policy() === 'without_discount'){ orderLine.get_unit_price() *
sum += ((orderLine.get_taxed_lst_unit_price() - orderLine.get_unit_price()) * orderLine.get_quantity()); (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; return sum;
} }
@@ -33,7 +33,7 @@
<span class="total-amount-formatting">TOTAL</span> <span class="total-amount-formatting">TOTAL</span>
</div> </div>
<div> <div>
<span class="pos_total-amount" t-esc="pos.format_currency(order and order.get_total_with_tax() || 0)"/> <span class="pos_total-amount" t-esc="formatCurrency(order and order.get_total_with_tax() || 0)"/>
</div> </div>
</div> </div>
@@ -63,7 +63,7 @@
<div><div t-attf-style="background-image:url(#{productImages[orderline.product.id]})"/></div> <div><div t-attf-style="background-image:url(#{productImages[orderline.product.id]})"/></div>
<div t-esc="orderline.get_full_product_name()"/> <div t-esc="orderline.get_full_product_name()"/>
<div t-esc="orderline.get_quantity_str()"/> <div t-esc="orderline.get_quantity_str()"/>
<div t-esc="pos.format_currency(orderline.get_display_price())"/> <div t-esc="formatCurrency(orderline.get_display_price())"/>
</div> </div>
</t> </t>
</div> </div>
@@ -78,7 +78,7 @@
<span><t t-esc="paymentline.name"/>:</span> <span><t t-esc="paymentline.name"/>:</span>
</div> </div>
<div> <div>
<span t-esc="pos.format_currency(paymentline.get_amount())"/> <span t-esc="formatCurrency(paymentline.get_amount())"/>
</div> </div>
</t> </t>
</t> </t>
@@ -87,7 +87,7 @@
<span class="pos-change_title">Change</span> <span class="pos-change_title">Change</span>
</div> </div>
<div> <div>
<span class="pos-change_amount" t-esc="pos.format_currency(order and order.get_change() || 0)"/> <span class="pos-change_amount" t-esc="formatCurrency(order and order.get_change() || 0)"/>
</div> </div>
</div> </div>
</t> </t>
@@ -7,7 +7,7 @@
<div class="title">Closing Session</div> <div class="title">Closing Session</div>
<div class="total-orders"> <div class="total-orders">
Total <t t-esc="ordersDetails.quantity"/> orders: Total <t t-esc="ordersDetails.quantity"/> orders:
<span class="amount" t-esc="pos.globalState.format_currency(ordersDetails.amount)"/> <span class="amount" t-esc="env.utils.formatCurrency(ordersDetails.amount)"/>
</div> </div>
</header> </header>
<main class="body"> <main class="body">
@@ -25,20 +25,20 @@
<tbody> <tbody>
<tr> <tr>
<td t-esc="defaultCashDetails.name"/> <td t-esc="defaultCashDetails.name"/>
<td t-esc="pos.globalState.format_currency(defaultCashDetails.amount)"/> <td t-esc="env.utils.formatCurrency(defaultCashDetails.amount)"/>
<td class="flex" t-on-input="() => this.handleInputChange(defaultCashDetails.id)"> <td class="flex" t-on-input="() => this.handleInputChange(defaultCashDetails.id)">
<input class="pos-input" type="number" t-model.number="state.payments[defaultCashDetails.id].counted"/> <input class="pos-input" type="number" t-model.number="state.payments[defaultCashDetails.id].counted"/>
<div class="button icon" t-on-click="openDetailsPopup"> <div class="button icon" t-on-click="openDetailsPopup">
<i class="fa fa-calculator" role="img" title="Open the money details popup"/> <i class="fa fa-calculator" role="img" title="Open the money details popup"/>
</div> </div>
</td> </td>
<td t-esc="pos.globalState.format_currency(state.payments[defaultCashDetails.id].difference)" t-att-class="{'warning': state.payments[defaultCashDetails.id].difference}"/> <td t-esc="env.utils.formatCurrency(state.payments[defaultCashDetails.id].difference)" t-att-class="{'warning': state.payments[defaultCashDetails.id].difference}"/>
</tr> </tr>
</tbody> </tbody>
<tbody class="cash-overview"> <tbody class="cash-overview">
<tr> <tr>
<td>Opening</td> <td>Opening</td>
<td t-esc="pos.globalState.format_currency(defaultCashDetails.opening)"/> <td t-esc="env.utils.formatCurrency(defaultCashDetails.opening)"/>
</tr> </tr>
<tr t-foreach="defaultCashDetails.moves" t-as="move" t-key="move_index"> <tr t-foreach="defaultCashDetails.moves" t-as="move" t-key="move_index">
<td> <td>
@@ -47,7 +47,7 @@
<t t-esc="move.name"/> <t t-esc="move.name"/>
</div> </div>
</td> </td>
<td t-esc="pos.globalState.format_currency(Math.abs(move.amount))"/> <td t-esc="env.utils.formatCurrency(Math.abs(move.amount))"/>
</tr> </tr>
<tr t-if="defaultCashDetails.payment_amount"> <tr t-if="defaultCashDetails.payment_amount">
<td> <td>
@@ -56,17 +56,17 @@
Payments in <t t-esc="defaultCashDetails.name"/> Payments in <t t-esc="defaultCashDetails.name"/>
</div> </div>
</td> </td>
<td t-esc="pos.globalState.format_currency(Math.abs(defaultCashDetails.payment_amount))"/> <td t-esc="env.utils.formatCurrency(Math.abs(defaultCashDetails.payment_amount))"/>
</tr> </tr>
</tbody> </tbody>
</t> </t>
<tbody t-if="otherPaymentMethods.length &gt; 0"> <tbody t-if="otherPaymentMethods.length &gt; 0">
<tr t-foreach="otherPaymentMethods" t-as="pm" t-key="pm.id"> <tr t-foreach="otherPaymentMethods" t-as="pm" t-key="pm.id">
<td t-esc="pm.name"/> <td t-esc="pm.name"/>
<td t-esc="pos.globalState.format_currency(pm.amount)"/> <td t-esc="env.utils.formatCurrency(pm.amount)"/>
<t t-set="_showDiff" t-value="_getShowDiff(pm)" /> <t t-set="_showDiff" t-value="_getShowDiff(pm)" />
<td t-if="_showDiff" t-on-input="() => this.handleInputChange(pm.id)"><input class="pos-input" type="number" t-model.number="state.payments[pm.id].counted"/></td> <td t-if="_showDiff" t-on-input="() => this.handleInputChange(pm.id)"><input class="pos-input" type="number" t-model.number="state.payments[pm.id].counted"/></td>
<td t-if="_showDiff" t-esc="pos.globalState.format_currency(state.payments[pm.id].difference)" t-att-class="{'warning': state.payments[pm.id].difference}"/> <td t-if="_showDiff" t-esc="env.utils.formatCurrency(state.payments[pm.id].difference)" t-att-class="{'warning': state.payments[pm.id].difference}"/>
</tr> </tr>
</tbody> </tbody>
</table> </table>
@@ -18,7 +18,7 @@
</div> </div>
<div class="total-section"> <div class="total-section">
<span>Total </span> <span>Total </span>
<CurrencyAmount currency="currency" amount="pos.globalState.format_currency_no_symbol(state.total)"/> <CurrencyAmount currency="currency" amount="env.utils.formatCurrency(state.total, false)"/>
</div> </div>
</main> </main>
<footer class="footer footer-flex"> <footer class="footer footer-flex">
@@ -39,7 +39,7 @@
</div> </div>
<div t-if="value.price_extra" class="price-extra-cell"> <div t-if="value.price_extra" class="price-extra-cell">
<span class="price_extra"> <span class="price_extra">
+ <t t-esc="pos.globalState.format_currency(value.price_extra)"/> + <t t-esc="env.utils.formatCurrency(value.price_extra)"/>
</span> </span>
</div> </div>
<div t-if="value.id == state.selected_value &amp;&amp; value.is_custom" class="custom-value-cell"> <div t-if="value.id == state.selected_value &amp;&amp; value.is_custom" class="custom-value-cell">
@@ -59,7 +59,7 @@
<t t-set="is_custom" t-value="is_custom || (value.is_custom &amp;&amp; value.id == state.selected_value)"/> <t t-set="is_custom" t-value="is_custom || (value.is_custom &amp;&amp; value.id == state.selected_value)"/>
<t t-esc="value.name"/> <t t-esc="value.name"/>
<t t-if="value.price_extra"> <t t-if="value.price_extra">
+ <t t-esc="pos.globalState.format_currency(value.price_extra)"/> + <t t-esc="env.utils.formatCurrency(value.price_extra)"/>
</t> </t>
</option> </option>
</select> </select>
@@ -12,9 +12,9 @@
<span><t t-if="props.product.default_code" t-esc="props.product.default_code"/> <t t-if="props.product.default_code and props.product.barcode"> - </t> <t t-if="props.product.barcode" t-esc="props.product.barcode"/></span> <span><t t-if="props.product.default_code" t-esc="props.product.default_code"/> <t t-if="props.product.default_code and props.product.barcode"> - </t> <t t-if="props.product.barcode" t-esc="props.product.barcode"/></span>
</div> </div>
<div class="column flex-end"> <div class="column flex-end">
<span t-esc="pos.globalState.format_currency(productInfo.all_prices.price_with_tax)" class="global-info-title" /> <span t-esc="env.utils.formatCurrency(productInfo.all_prices.price_with_tax)" class="global-info-title" />
<t t-foreach="productInfo.all_prices.tax_details" t-as="tax" t-key="tax.name"> <t t-foreach="productInfo.all_prices.tax_details" t-as="tax" t-key="tax.name">
<div><t t-esc="tax.name"/>: <t t-esc="pos.globalState.format_currency(tax.amount)"/></div> <div><t t-esc="tax.name"/>: <t t-esc="env.utils.formatCurrency(tax.amount)"/></div>
</t> </t>
</div> </div>
</div> </div>
@@ -27,7 +27,7 @@
<table> <table>
<tr> <tr>
<td>Price excl. VAT:</td> <td>Price excl. VAT:</td>
<td><t t-esc="pos.globalState.format_currency(productInfo.all_prices.price_without_tax)"/></td> <td><t t-esc="env.utils.formatCurrency(productInfo.all_prices.price_without_tax)"/></td>
</tr> </tr>
<tr t-if="_hasMarginsCostsAccessRights()"> <tr t-if="_hasMarginsCostsAccessRights()">
<td>Cost:</td> <td>Cost:</td>
@@ -42,7 +42,7 @@
<t t-foreach="productInfo.pricelists" t-as="pricelist" t-key="pricelist.name"> <t t-foreach="productInfo.pricelists" t-as="pricelist" t-key="pricelist.name">
<tr> <tr>
<td t-esc="pricelist.name"/> <td t-esc="pricelist.name"/>
<td t-esc="pos.globalState.format_currency(pricelist.price)"/> <td t-esc="env.utils.formatCurrency(pricelist.price)"/>
</tr> </tr>
</t> </t>
</table> </table>
@@ -77,7 +77,7 @@
<td><span t-esc="supplier.name" class="table-name"/>:</td> <td><span t-esc="supplier.name" class="table-name"/>:</td>
<div class="mobile-line"> <div class="mobile-line">
<td><t t-esc="supplier.delay"/> Days</td> <td><t t-esc="supplier.delay"/> Days</td>
<td t-if="_hasMarginsCostsAccessRights()"><t t-esc="pos.globalState.format_currency(supplier.price)"/></td> <td t-if="_hasMarginsCostsAccessRights()"><t t-esc="env.utils.formatCurrency(supplier.price)"/></td>
</div> </div>
</tr> </tr>
</t> </t>
@@ -28,7 +28,7 @@
<t t-esc="line.uom" /> <t t-esc="line.uom" />
</t> </t>
x x
<t t-esc="pos.format_currency_no_symbol(line.price_unit)" /> <t t-esc="formatCurrency(line.price_unit, false)" />
</span> </span>
</div> </div>
<t t-if="line.discount !== 0"> <t t-if="line.discount !== 0">
@@ -57,7 +57,7 @@
<t t-esc="line.uom" /> <t t-esc="line.uom" />
</t> </t>
x x
<t t-esc="pos.format_currency_no_symbol(line.price_unit)" /> <t t-esc="formatCurrency(line.price_unit, false)" />
</span> </span>
</div> </div>
<t t-if="line.discount !== 0"> <t t-if="line.discount !== 0">
@@ -76,7 +76,7 @@
</div> </div>
<div t-foreach="payments" t-as="payment" t-key="payment_index"> <div t-foreach="payments" t-as="payment" t-key="payment_index">
<t t-esc="payment['name']" /> <t t-esc="payment['name']" />
<span t-esc="pos.format_currency_no_symbol(payment['total'])" class="pos-receipt-right-align"/> <span t-esc="formatCurrency(payment['total'], false)" class="pos-receipt-right-align"/>
</div> </div>
<br/> <br/>
@@ -88,7 +88,7 @@
</div> </div>
<div t-foreach="taxes" t-as="tax" t-key="tax_index"> <div t-foreach="taxes" t-as="tax" t-key="tax_index">
<t t-esc="tax.name" /> <t t-esc="tax.name" />
<span t-esc="pos.format_currency_no_symbol(tax.tax_amount)" class="pos-receipt-right-align"/> <span t-esc="formatCurrency(tax.tax_amount, false)" class="pos-receipt-right-align"/>
</div> </div>
<br/> <br/>
@@ -97,7 +97,7 @@
<div> <div>
Total: Total:
<span t-esc="pos.format_currency_no_symbol(total_paid)" class="pos-receipt-right-align"/> <span t-esc="formatCurrency(total_paid, false)" class="pos-receipt-right-align"/>
</div> </div>
<br/> <br/>
@@ -90,7 +90,7 @@
<div t-if="env.pos.config.tip_product_id" class="button js_tip" <div t-if="env.pos.config.tip_product_id" class="button js_tip"
t-att-class="{ highlight: currentOrder.get_tip() }" t-att-class="{ highlight: currentOrder.get_tip() }"
t-on-click="addTip"> t-on-click="addTip">
<i class="fa fa-heart" /> Tip <t t-if="currentOrder.get_tip() != 0">(<t t-esc="env.pos.format_currency(currentOrder.get_tip())"/>)</t> <i class="fa fa-heart" /> Tip <t t-if="currentOrder.get_tip() != 0">(<t t-esc="env.utils.formatCurrency(currentOrder.get_tip())"/>)</t>
</div> </div>
<div t-if="env.pos.config.iface_cashdrawer" class="button js_cashdrawer" <div t-if="env.pos.config.iface_cashdrawer" class="button js_cashdrawer"
t-on-click="openCashbox"> t-on-click="openCashbox">
@@ -14,7 +14,7 @@
</div> </div>
<div class="payment-amount"> <div class="payment-amount">
<t t-if="line and line.payment_status and ['done', 'waitingCard', 'waiting', 'reversing', 'reversed'].includes(line.payment_status)"> <t t-if="line and line.payment_status and ['done', 'waitingCard', 'waiting', 'reversing', 'reversed'].includes(line.payment_status)">
<t t-esc="env.pos.format_currency_no_symbol(line.get_amount())" /> <t t-esc="env.utils.formatCurrency(line.get_amount(), false)" />
</t> </t>
<t t-else=""> <t t-else="">
<t t-esc="formatLineAmount(line)" /> <t t-esc="formatLineAmount(line)" />
@@ -109,7 +109,7 @@
</div> </div>
<div class="payment-amount"> <div class="payment-amount">
<t t-if="line and line.payment_status and ['done', 'waitingCard', 'waiting', 'reversing', 'reversed'].includes(line.payment_status)"> <t t-if="line and line.payment_status and ['done', 'waitingCard', 'waiting', 'reversing', 'reversed'].includes(line.payment_status)">
<t t-esc="env.pos.format_currency_no_symbol(line.get_amount())" /> <t t-esc="env.utils.formatCurrency(line.get_amount(), false)" />
</t> </t>
<t t-else=""> <t t-else="">
<t t-esc="formatLineAmount(line)" /> <t t-esc="formatLineAmount(line)" />
@@ -26,7 +26,7 @@
</t> </t>
</span> </span>
<span class="price"> <span class="price">
<t t-esc="env.pos.format_currency(props.line.get_display_price())"/> <t t-esc="env.utils.formatCurrency(props.line.get_display_price())"/>
</span> </span>
<ul class="info-list"> <ul class="info-list">
<t t-if="props.line.get_quantity_str() !== '1' || props.line.selected "> <t t-if="props.line.get_quantity_str() !== '1' || props.line.selected ">
@@ -39,12 +39,12 @@
<t t-if="props.line.display_discount_policy() == 'without_discount' and <t t-if="props.line.display_discount_policy() == 'without_discount' and
env.pos.round_decimals_currency(props.line.get_unit_display_price()) &lt; env.pos.round_decimals_currency(props.line.get_taxed_lst_unit_price())"> env.pos.round_decimals_currency(props.line.get_unit_display_price()) &lt; env.pos.round_decimals_currency(props.line.get_taxed_lst_unit_price())">
<s> <s>
<t t-esc="env.pos.format_currency(props.line.get_taxed_lst_unit_price(),'Product Price')" /> <t t-esc="env.utils.formatCurrency(props.line.get_taxed_lst_unit_price())" />
</s> </s>
<t t-esc="env.pos.format_currency(props.line.get_unit_display_price(),'Product Price')" /> <t t-esc="env.utils.formatCurrency(props.line.get_unit_display_price())" />
</t> </t>
<t t-else=""> <t t-else="">
<t t-esc="env.pos.format_currency(props.line.get_unit_display_price(),'Product Price')" /> <t t-esc="env.utils.formatCurrency(props.line.get_unit_display_price())" />
</t> </t>
/ /
<t t-esc="props.line.get_unit().name" /> <t t-esc="props.line.get_unit().name" />
@@ -52,11 +52,11 @@
<t t-if="!isTaxIncluded"> <t t-if="!isTaxIncluded">
<div class="pos-receipt-right-align">--------</div> <div class="pos-receipt-right-align">--------</div>
<br/> <br/>
<div>Subtotal<span t-esc="env.pos.format_currency(receipt.subtotal)" class="pos-receipt-right-align"/></div> <div>Subtotal<span t-esc="env.utils.formatCurrency(receipt.subtotal)" class="pos-receipt-right-align"/></div>
<t t-foreach="receipt.tax_details" t-as="tax" t-key="tax.name"> <t t-foreach="receipt.tax_details" t-as="tax" t-key="tax.name">
<div class="responsive-price"> <div class="responsive-price">
<t t-esc="tax.name" /> <t t-esc="tax.name" />
<span t-esc='env.pos.format_currency_no_symbol(tax.amount)' class="pos-receipt-right-align"/> <span t-esc='env.utils.formatCurrency(tax.amount, false)' class="pos-receipt-right-align"/>
</div> </div>
</t> </t>
</t> </t>
@@ -66,16 +66,16 @@
<br/> <br/>
<div class="pos-receipt-amount"> <div class="pos-receipt-amount">
TOTAL TOTAL
<span t-esc="env.pos.format_currency(receipt.total_with_tax)" class="pos-receipt-right-align"/> <span t-esc="env.utils.formatCurrency(receipt.total_with_tax)" class="pos-receipt-right-align"/>
</div> </div>
<t t-if="receipt.total_rounded != receipt.total_with_tax"> <t t-if="receipt.total_rounded != receipt.total_with_tax">
<div class="pos-receipt-amount"> <div class="pos-receipt-amount">
Rounding Rounding
<span t-esc='env.pos.format_currency(receipt.rounding_applied)' class="pos-receipt-right-align"/> <span t-esc='env.utils.formatCurrency(receipt.rounding_applied)' class="pos-receipt-right-align"/>
</div> </div>
<div class="pos-receipt-amount"> <div class="pos-receipt-amount">
To Pay To Pay
<span t-esc='env.pos.format_currency(receipt.total_rounded)' class="pos-receipt-right-align"/> <span t-esc='env.utils.formatCurrency(receipt.total_rounded)' class="pos-receipt-right-align"/>
</div> </div>
</t> </t>
<br/><br/> <br/><br/>
@@ -85,14 +85,14 @@
<t t-foreach="receipt.paymentlines" t-as="line" t-key="line.cid"> <t t-foreach="receipt.paymentlines" t-as="line" t-key="line.cid">
<div> <div>
<t t-esc="line.name" /> <t t-esc="line.name" />
<span t-esc="env.pos.format_currency_no_symbol(line.amount)" class="pos-receipt-right-align"/> <span t-esc="env.utils.formatCurrency(line.amount, false)" class="pos-receipt-right-align"/>
</div> </div>
</t> </t>
<br/> <br/>
<div class="pos-receipt-amount receipt-change"> <div class="pos-receipt-amount receipt-change">
CHANGE CHANGE
<span t-esc="env.pos.format_currency(receipt.change)" class="pos-receipt-right-align"/> <span t-esc="env.utils.formatCurrency(receipt.change)" class="pos-receipt-right-align"/>
</div> </div>
<br/> <br/>
@@ -101,19 +101,19 @@
<t t-if="receipt.total_discount"> <t t-if="receipt.total_discount">
<div> <div>
Discounts Discounts
<span t-esc="env.pos.format_currency(receipt.total_discount)" class="pos-receipt-right-align"/> <span t-esc="env.utils.formatCurrency(receipt.total_discount)" class="pos-receipt-right-align"/>
</div> </div>
</t> </t>
<t t-if="isTaxIncluded"> <t t-if="isTaxIncluded">
<t t-foreach="receipt.tax_details" t-as="tax" t-key="tax.name"> <t t-foreach="receipt.tax_details" t-as="tax" t-key="tax.name">
<div> <div>
<t t-esc="tax.name" /> <t t-esc="tax.name" />
<span t-esc="env.pos.format_currency_no_symbol(tax.amount)" class="pos-receipt-right-align"/> <span t-esc="env.utils.formatCurrency(tax.amount, false)" class="pos-receipt-right-align"/>
</div> </div>
</t> </t>
<div id="post_receipt_taxes_container"> <div id="post_receipt_taxes_container">
Total Taxes Total Taxes
<span t-esc="env.pos.format_currency(receipt.total_tax)" class="pos-receipt-right-align"/> <span t-esc="env.utils.formatCurrency(receipt.total_tax)" class="pos-receipt-right-align"/>
</div> </div>
</t> </t>
@@ -181,7 +181,7 @@
<t t-if="isSimple(line)"> <t t-if="isSimple(line)">
<div class="responsive-price"> <div class="responsive-price">
<t t-esc="line.product_name_wrapped[0]" /> <t t-esc="line.product_name_wrapped[0]" />
<span t-esc="env.pos.format_currency_no_symbol(line.price_display)" class="price_display pos-receipt-right-align"/> <span t-esc="env.utils.formatCurrency(line.price_display, false)" class="price_display pos-receipt-right-align"/>
</div> </div>
<WrappedProductNameLines line="line" /> <WrappedProductNameLines line="line" />
</t> </t>
@@ -190,18 +190,18 @@
<WrappedProductNameLines line="line" /> <WrappedProductNameLines line="line" />
<t t-if="line.display_discount_policy == 'without_discount' and line.price != line.price_lst"> <t t-if="line.display_discount_policy == 'without_discount' and line.price != line.price_lst">
<div class="pos-receipt-left-padding"> <div class="pos-receipt-left-padding">
<t t-esc="env.pos.format_currency_no_symbol(line.price_lst)" /> <t t-esc="env.utils.formatCurrency(line.price_lst, false)" />
-> ->
<t t-esc="env.pos.format_currency_no_symbol(line.price)" /> <t t-esc="env.utils.formatCurrency(line.price, false)" />
</div> </div>
</t> </t>
<t t-elif="line.discount !== 0"> <t t-elif="line.discount !== 0">
<div class="pos-receipt-left-padding"> <div class="pos-receipt-left-padding">
<t t-if="env.pos.config.iface_tax_included === 'total'"> <t t-if="env.pos.config.iface_tax_included === 'total'">
<t t-esc="env.pos.format_currency_no_symbol(line.price_with_tax_before_discount)"/> <t t-esc="env.utils.formatCurrency(line.price_with_tax_before_discount, false)"/>
</t> </t>
<t t-else=""> <t t-else="">
<t t-esc="env.pos.format_currency_no_symbol(line.price)"/> <t t-esc="env.utils.formatCurrency(line.price, false)"/>
</t> </t>
</div> </div>
</t> </t>
@@ -214,9 +214,9 @@
<t t-esc="Math.round(line.quantity * Math.pow(10, env.pos.dp['Product Unit of Measure'])) / Math.pow(10, env.pos.dp['Product Unit of Measure'])"/> <t t-esc="Math.round(line.quantity * Math.pow(10, env.pos.dp['Product Unit of Measure'])) / Math.pow(10, env.pos.dp['Product Unit of Measure'])"/>
<t t-if="!line.is_in_unit" t-esc="line.unit_name" /> <t t-if="!line.is_in_unit" t-esc="line.unit_name" />
x x
<t t-esc="env.pos.format_currency(line.price_display_one)" /> <t t-esc="env.utils.formatCurrency(line.price_display_one)" />
<span class="price_display pos-receipt-right-align"> <span class="price_display pos-receipt-right-align">
<t t-esc="env.pos.format_currency_no_symbol(line.price_display)" /> <t t-esc="env.utils.formatCurrency(line.price_display, false)" />
</span> </span>
</div> </div>
</t> </t>
@@ -19,7 +19,7 @@
</div> </div>
<div class="product-price"> <div class="product-price">
<t <t
t-esc="env.pos.format_currency(productPrice) + '/' + productUom" /> t-esc="env.utils.formatCurrency(productPrice) + '/' + productUom" />
</div> </div>
<div class="computed-price"> <div class="computed-price">
<t t-esc="computedPriceString" /> <t t-esc="computedPriceString" />
@@ -7,6 +7,7 @@ import { Chrome } from "@point_of_sale/../tests/tours/helpers/ChromeTourMethods"
import { NumberPopup } from "@point_of_sale/../tests/tours/helpers/NumberPopupTourMethods"; import { NumberPopup } from "@point_of_sale/../tests/tours/helpers/NumberPopupTourMethods";
import { getSteps, startSteps } from "@point_of_sale/../tests/tours/helpers/utils"; import { getSteps, startSteps } from "@point_of_sale/../tests/tours/helpers/utils";
import { registry } from "@web/core/registry"; import { registry } from "@web/core/registry";
import { nbsp } from "@web/core/utils/strings";
startSteps(); startSteps();
@@ -54,7 +55,7 @@ PaymentScreen.check.emptyPaymentlines("31.0");
PaymentScreen.do.clickPaymentMethod("Cash"); PaymentScreen.do.clickPaymentMethod("Cash");
PaymentScreen.do.clickValidate(); PaymentScreen.do.clickValidate();
ReceiptScreen.check.receiptIsThere(); ReceiptScreen.check.receiptIsThere();
ReceiptScreen.check.totalAmountContains("$ 30.00 + $ 1.00 tip"); ReceiptScreen.check.totalAmountContains(`$${nbsp}30.00 + $${nbsp}1.00 tip`);
ReceiptScreen.do.clickNextOrder(); ReceiptScreen.do.clickNextOrder();
// Test customer note in receipt // Test customer note in receipt
@@ -3,6 +3,7 @@
import { registry } from "@web/core/registry"; import { registry } from "@web/core/registry";
import { roundDecimals as round_di } from "@web/core/utils/numbers"; import { roundDecimals as round_di } from "@web/core/utils/numbers";
import { nbsp } from "@web/core/utils/strings";
function assert(condition, message) { function assert(condition, message) {
if (!condition) { if (!condition) {
@@ -192,7 +193,7 @@ steps = steps.concat([
}, },
{ {
content: "verify that unit price of shelf changed to $1", content: "verify that unit price of shelf changed to $1",
trigger: ".total > .value:contains('$ 2.00')", trigger: `.total > .value:contains('$${nbsp}2.00')`,
run: function () {}, run: function () {},
}, },
{ {
@@ -247,7 +248,7 @@ steps = steps.concat([
{ {
content: content:
"verify that the boni shelf have been recomputed and the shelf have not (their price was manually overridden)", "verify that the boni shelf have been recomputed and the shelf have not (their price was manually overridden)",
trigger: ".total > .value:contains('$ 8.96')", trigger: `.total > .value:contains('$${nbsp}8.96')`,
}, },
{ {
content: "click pricelist button", content: "click pricelist button",
@@ -24,8 +24,8 @@ patch(Orderline.prototype, "pos_loyalty.Orderline", {
_getGiftCardOrEWalletBalance() { _getGiftCardOrEWalletBalance() {
const coupon = this.env.pos.couponCache[this.props.line.coupon_id]; const coupon = this.env.pos.couponCache[this.props.line.coupon_id];
if (coupon) { if (coupon) {
return this.env.pos.format_currency(coupon.balance); return this.env.utils.formatCurrency(coupon.balance);
} }
return this.env.pos.format_currency(0); return this.env.utils.formatCurrency(0);
}, },
}); });
@@ -8,7 +8,7 @@ patch(PartnerLine.prototype, "pos_loyalty.PartnerLine", {
_getLoyaltyPointsRepr(loyaltyCard) { _getLoyaltyPointsRepr(loyaltyCard) {
const program = this.env.pos.program_by_id[loyaltyCard.program_id]; const program = this.env.pos.program_by_id[loyaltyCard.program_id];
if (program.program_type === "ewallet") { if (program.program_type === "ewallet") {
return `${program.name}: ${this.env.pos.format_currency(loyaltyCard.balance)}`; return `${program.name}: ${this.env.utils.formatCurrency(loyaltyCard.balance)}`;
} }
const balanceRepr = this.env.pos.format_pr(loyaltyCard.balance, 0.01); const balanceRepr = this.env.pos.format_pr(loyaltyCard.balance, 0.01);
if (program.portal_visible) { if (program.portal_visible) {
@@ -160,7 +160,7 @@ export class TipCell extends Component {
useAutofocus(); useAutofocus();
} }
get tipAmountStr() { get tipAmountStr() {
return this.env.pos.format_currency(parseFloat(this.orderUiState.inputTipAmount || "0")); return this.env.utils.formatCurrency(parseFloat(this.orderUiState.inputTipAmount || "0"));
} }
onBlur() { onBlur() {
this.state.isEditing = false; this.state.isEditing = false;
@@ -28,9 +28,9 @@ export class TipScreen extends Component {
} }
get overallAmountStr() { get overallAmountStr() {
const tipAmount = parseFloat(this.state.inputTipAmount || "0"); const tipAmount = parseFloat(this.state.inputTipAmount || "0");
const original = this.env.pos.format_currency(this.totalAmount); const original = this.env.utils.formatCurrency(this.totalAmount);
const tip = this.env.pos.format_currency(tipAmount); const tip = this.env.utils.formatCurrency(tipAmount);
const overall = this.env.pos.format_currency(this.totalAmount + tipAmount); const overall = this.env.utils.formatCurrency(this.totalAmount + tipAmount);
return `${original} + ${tip} tip = ${overall}`; return `${original} + ${tip} tip = ${overall}`;
} }
get totalAmount() { get totalAmount() {
@@ -70,7 +70,7 @@ export class TipScreen extends Component {
if (amount > 0.25 * this.totalAmount) { if (amount > 0.25 * this.totalAmount) {
const { confirmed } = await this.popup.add(ConfirmPopup, { const { confirmed } = await this.popup.add(ConfirmPopup, {
title: "Are you sure?", title: "Are you sure?",
body: `${this.env.pos.format_currency( body: `${this.env.utils.formatCurrency(
amount amount
)} is more than 25% of the order's total amount. Are you sure of this tip amount?`, )} is more than 25% of the order's total amount. Are you sure of this tip amount?`,
}); });
@@ -122,7 +122,7 @@ export class TipScreen extends Component {
var receipt = renderToElement("TipReceipt", { var receipt = renderToElement("TipReceipt", {
receipt: this.currentOrder.getOrderReceiptEnv().receipt, receipt: this.currentOrder.getOrderReceiptEnv().receipt,
data: data, data: data,
total: this.env.pos.format_currency(this.totalAmount), total: this.env.utils.formatCurrency(this.totalAmount),
}); });
if (this.hardwareProxy.printer) { if (this.hardwareProxy.printer) {
@@ -26,19 +26,19 @@
<div class="option"> <div class="option">
<div>15%</div> <div>15%</div>
<div class="amount"> <div class="amount">
<t t-esc="env.pos.format_currency(receipt.total_with_tax * 0.15)"></t> <t t-esc="env.utils.formatCurrency(receipt.total_with_tax * 0.15)"></t>
</div> </div>
</div> </div>
<div class="option"> <div class="option">
<div>20%</div> <div>20%</div>
<div class="amount"> <div class="amount">
<t t-esc="env.pos.format_currency(receipt.total_with_tax * 0.20)"></t> <t t-esc="env.utils.formatCurrency(receipt.total_with_tax * 0.20)"></t>
</div> </div>
</div> </div>
<div class="option"> <div class="option">
<div>25%</div> <div>25%</div>
<div class="amount"> <div class="amount">
<t t-esc="env.pos.format_currency(receipt.total_with_tax * 0.25)"></t> <t t-esc="env.utils.formatCurrency(receipt.total_with_tax * 0.25)"></t>
</div> </div>
</div> </div>
</div> </div>
@@ -30,7 +30,7 @@
<div class="controls"> <div class="controls">
<div class="order-info"> <div class="order-info">
<span class="subtotal"> <span class="subtotal">
<t t-esc="env.pos.format_currency(newOrder.get_subtotal())" /> <t t-esc="env.utils.formatCurrency(newOrder.get_subtotal())" />
</span> </span>
</div> </div>
<div class="pay-button"> <div class="pay-button">
@@ -7,7 +7,7 @@
<t t-esc="props.line.get_product().display_name" /> <t t-esc="props.line.get_product().display_name" />
</span> </span>
<span class="price"> <span class="price">
<t t-esc="env.pos.format_currency(props.line.get_display_price())" /> <t t-esc="env.utils.formatCurrency(props.line.get_display_price())" />
</span> </span>
<ul class="info-list"> <ul class="info-list">
<t t-if="props.line.get_quantity_str() !== '1'"> <t t-if="props.line.get_quantity_str() !== '1'">
@@ -26,7 +26,7 @@
</t> </t>
<t t-esc="props.line.get_unit().name" /> <t t-esc="props.line.get_unit().name" />
at at
<t t-esc="env.pos.format_currency(props.line.get_unit_price())" /> <t t-esc="env.utils.formatCurrency(props.line.get_unit_price())" />
/ /
<t t-esc="props.line.get_unit().name" /> <t t-esc="props.line.get_unit().name" />
</li> </li>
@@ -35,7 +35,7 @@
<t t-esc="tip.percentage"></t> <t t-esc="tip.percentage"></t>
</div> </div>
<div class="amount"> <div class="amount">
<t t-esc="env.pos.format_currency(tip.amount)" /> <t t-esc="env.utils.formatCurrency(tip.amount)" />
</div> </div>
</div> </div>
</t> </t>
@@ -285,7 +285,7 @@ export class SaleOrderManagementScreen extends ControlButtonsMixin(IndependentTo
const { confirmed, payload } = await this.popup.add(NumberPopup, { const { confirmed, payload } = await this.popup.add(NumberPopup, {
title: sprintf( title: sprintf(
this.env._t("Percentage of %s"), this.env._t("Percentage of %s"),
this.env.pos.format_currency(sale_order.amount_total) this.env.utils.formatCurrency(sale_order.amount_total)
), ),
startingValue: 0, startingValue: 0,
}); });
@@ -298,11 +298,11 @@ export class SaleOrderManagementScreen extends ControlButtonsMixin(IndependentTo
this.env._t( this.env._t(
"You have tried to charge a down payment of %s but only %s remains to be paid, %s will be applied to the purchase order line." "You have tried to charge a down payment of %s but only %s remains to be paid, %s will be applied to the purchase order line."
), ),
this.env.pos.format_currency(down_payment), this.env.utils.formatCurrency(down_payment),
this.env.pos.format_currency(sale_order.amount_unpaid), this.env.utils.formatCurrency(sale_order.amount_unpaid),
sale_order.amount_unpaid > 0 sale_order.amount_unpaid > 0
? this.env.pos.format_currency(sale_order.amount_unpaid) ? this.env.utils.formatCurrency(sale_order.amount_unpaid)
: this.env.pos.format_currency(0) : this.env.utils.formatCurrency(0)
); );
await this.popup.add(ErrorPopup, { await this.popup.add(ErrorPopup, {
title: "Error amount too high", title: "Error amount too high",
@@ -32,7 +32,7 @@ export class SaleOrderRow extends Component {
return partner ? partner[1] : null; return partner ? partner[1] : null;
} }
get total() { get total() {
return this.env.pos.format_currency(this.order.amount_total); return this.env.utils.formatCurrency(this.order.amount_total);
} }
/** /**
* Returns true if the order has unpaid amount, but the unpaid amount * Returns true if the order has unpaid amount, but the unpaid amount
@@ -43,7 +43,7 @@ export class SaleOrderRow extends Component {
return this.order.amount_total != this.order.amount_unpaid; return this.order.amount_total != this.order.amount_unpaid;
} }
get amountUnpaidRepr() { get amountUnpaidRepr() {
return this.env.pos.format_currency(this.order.amount_unpaid); return this.env.utils.formatCurrency(this.order.amount_unpaid);
} }
get state() { get state() {
const state_mapping = { const state_mapping = {
@@ -16,7 +16,7 @@
<t t-esc="line['product_name']" /> <t t-esc="line['product_name']" />
</td> </td>
<td>:</td> <td>:</td>
<td><t t-esc="env.pos.format_currency(line['total'])" /> (tax incl.)</td> <td><t t-esc="env.utils.formatCurrency(line['total'])" /> (tax incl.)</td>
</tr> </tr>
</t> </t>
</table> </table>
@@ -13,7 +13,7 @@
<tr> <tr>
<td><span class="searchable" t-esc="optional.name" t-on-click="() => this.searchProduct(optional.name)"/></td> <td><span class="searchable" t-esc="optional.name" t-on-click="() => this.searchProduct(optional.name)"/></td>
<td class="table-value"> <td class="table-value">
from <t t-esc="pos.globalState.format_currency(optional.price)"/> from <t t-esc="env.utils.formatCurrency(optional.price)"/>
</td> </td>
</tr> </tr>
</t> </t>