refactor: implement safe currency formatting utility to ensure consistent currency rendering in POS closing receipts
This commit is contained in:
parent
733d52e2d7
commit
43f92c39a2
@ -10,9 +10,42 @@ import { ConnectionLostError } from "@web/core/network/rpc";
|
|||||||
import { _t } from "@web/core/l10n/translation";
|
import { _t } from "@web/core/l10n/translation";
|
||||||
import { PrinterService } from "@point_of_sale/app/services/printer_service";
|
import { PrinterService } from "@point_of_sale/app/services/printer_service";
|
||||||
import { waitImages } from "@point_of_sale/utils";
|
import { waitImages } from "@point_of_sale/utils";
|
||||||
|
import { formatCurrency as webFormatCurrency } from "@web/core/currency";
|
||||||
|
|
||||||
ClosePosPopup.props.push("last_cashier_name?");
|
ClosePosPopup.props.push("last_cashier_name?");
|
||||||
|
|
||||||
|
const getCurrencyId = (pos) => {
|
||||||
|
if (!pos) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
if (pos.currency && typeof pos.currency === "object" && "id" in pos.currency) {
|
||||||
|
return pos.currency.id;
|
||||||
|
}
|
||||||
|
if (pos.currency && typeof pos.currency === "number") {
|
||||||
|
return pos.currency;
|
||||||
|
}
|
||||||
|
const configCurrency = pos.config?.currency_id;
|
||||||
|
if (configCurrency) {
|
||||||
|
if (typeof configCurrency === "object") {
|
||||||
|
if ("id" in configCurrency) {
|
||||||
|
return configCurrency.id;
|
||||||
|
}
|
||||||
|
if (Array.isArray(configCurrency)) {
|
||||||
|
return configCurrency[0];
|
||||||
|
}
|
||||||
|
} else if (typeof configCurrency === "number") {
|
||||||
|
return configCurrency;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
};
|
||||||
|
|
||||||
|
const safeFormatCurrency = (value, pos, hasSymbol = true) => {
|
||||||
|
return webFormatCurrency(value, getCurrencyId(pos), {
|
||||||
|
noSymbol: !hasSymbol,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
// Patch PrinterService.printWeb to return a promise that resolves only after print dialog is closed
|
// Patch PrinterService.printWeb to return a promise that resolves only after print dialog is closed
|
||||||
patch(PrinterService.prototype, {
|
patch(PrinterService.prototype, {
|
||||||
@ -308,7 +341,7 @@ patch(ClosePosPopup.prototype, {
|
|||||||
|
|
||||||
_buildReceiptData(sessionName) {
|
_buildReceiptData(sessionName) {
|
||||||
const pos = this.pos;
|
const pos = this.pos;
|
||||||
const formatCurrency = this.env.utils.formatCurrency;
|
const formatCurrency = (val, hasSymbol = true) => safeFormatCurrency(val, pos, hasSymbol);
|
||||||
|
|
||||||
let cashierName = this.props.last_cashier_name || "";
|
let cashierName = this.props.last_cashier_name || "";
|
||||||
if (!cashierName) {
|
if (!cashierName) {
|
||||||
@ -384,7 +417,8 @@ patch(ClosePosPopup.prototype, {
|
|||||||
// ─────────────────────────────────────────────────────────────────────────────
|
// ─────────────────────────────────────────────────────────────────────────────
|
||||||
patch(Navbar.prototype, {
|
patch(Navbar.prototype, {
|
||||||
async reprintLastClosingReceipt() {
|
async reprintLastClosingReceipt() {
|
||||||
const formatCurrency = this.env.utils.formatCurrency;
|
const pos = this.pos;
|
||||||
|
const formatCurrency = (val, hasSymbol = true) => safeFormatCurrency(val, pos, hasSymbol);
|
||||||
|
|
||||||
// ── 1. Fetch the last closed session for this config ─────────────────
|
// ── 1. Fetch the last closed session for this config ─────────────────
|
||||||
let sessionData;
|
let sessionData;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user