feat: add support for basic receipt mode by conditionally hiding prices and totals in escpos generator
This commit is contained in:
parent
a4a2f936f4
commit
2858ef1cc4
@ -241,27 +241,35 @@ export class EscPosGenerator {
|
|||||||
receiptData.lines.forEach(line => {
|
receiptData.lines.forEach(line => {
|
||||||
const name = String(line.productName || '');
|
const name = String(line.productName || '');
|
||||||
const qty = line.quantity || 0;
|
const qty = line.quantity || 0;
|
||||||
const unitPrice = line.price || 0;
|
const qtyStr = qty % 1 === 0 ? qty.toFixed(0) : qty.toFixed(2);
|
||||||
const total = line.total || 0;
|
|
||||||
|
|
||||||
// Line 1: product name (truncate to full width)
|
if (receiptData.isBasicReceipt) {
|
||||||
const displayName = name.length > W ? name.substring(0, W - 1) + '.' : name;
|
// ── Basic receipt / table checker ──────────────────────────
|
||||||
cmds.push(...this.addLine(displayName, { bold: false }));
|
// Show only qty + product name (no price/total), matching
|
||||||
|
// Odoo's basic_receipt behaviour (vals.price = false).
|
||||||
|
// Format: "2 Mie Ayam Geprek"
|
||||||
|
const qtyLabel = qtyStr.padEnd(3);
|
||||||
|
const nameMaxLen = W - qtyLabel.length;
|
||||||
|
const displayName = name.length > nameMaxLen
|
||||||
|
? name.substring(0, nameMaxLen - 1) + '.'
|
||||||
|
: name;
|
||||||
|
cmds.push(...this.addLine(qtyLabel + displayName));
|
||||||
|
} else {
|
||||||
|
// ── Full receipt ───────────────────────────────────────────
|
||||||
|
// Line 1: product name
|
||||||
|
const displayName = name.length > W ? name.substring(0, W - 1) + '.' : name;
|
||||||
|
cmds.push(...this.addLine(displayName));
|
||||||
|
|
||||||
// Line 2: qty x unitPrice = total (right-aligned)
|
// Line 2: qty x unitPrice = total (right-aligned)
|
||||||
const priceStr = this.formatAmount(unitPrice);
|
const priceStr = this.formatAmount(line.price || 0);
|
||||||
const totalStr = this.formatAmount(total);
|
const totalStr = this.formatAmount(line.total || 0);
|
||||||
const qtyStr = `${qty % 1 === 0 ? qty.toFixed(0) : qty.toFixed(2)}x`;
|
const middle = `${qtyStr}x ${priceStr}`;
|
||||||
// Build: " 2x 14.985.000 29.970.000"
|
let itemLine = middle + totalStr.padStart(W - middle.length);
|
||||||
const middle = `${qtyStr} ${priceStr}`;
|
if (itemLine.length > W) itemLine = totalStr.padStart(W);
|
||||||
let itemLine = middle + totalStr.padStart(W - middle.length);
|
cmds.push(...this.addLine(itemLine));
|
||||||
if (itemLine.length > W) {
|
|
||||||
// fallback: just right-align total
|
|
||||||
itemLine = totalStr.padStart(W);
|
|
||||||
}
|
}
|
||||||
cmds.push(...this.addLine(itemLine));
|
|
||||||
|
|
||||||
// Line 3 (optional): customer note / kitchen note
|
// Note line (customer note / kitchen note) — shown on both modes
|
||||||
if (line.note) {
|
if (line.note) {
|
||||||
const noteText = `* ${line.note}`;
|
const noteText = `* ${line.note}`;
|
||||||
cmds.push(...this.addLine(
|
cmds.push(...this.addLine(
|
||||||
@ -273,7 +281,8 @@ export class EscPosGenerator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ── Totals ────────────────────────────────────────────────────────
|
// ── Totals ────────────────────────────────────────────────────────
|
||||||
if (receiptData.totals) {
|
// Hidden on basic receipt — matches t-if="!props.basic_receipt" in order_receipt.xml
|
||||||
|
if (!receiptData.isBasicReceipt && receiptData.totals) {
|
||||||
const t = receiptData.totals;
|
const t = receiptData.totals;
|
||||||
|
|
||||||
if (t.subtotal !== undefined) {
|
if (t.subtotal !== undefined) {
|
||||||
@ -298,7 +307,8 @@ export class EscPosGenerator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ── Payment ───────────────────────────────────────────────────────
|
// ── Payment ───────────────────────────────────────────────────────
|
||||||
if (receiptData.paymentData) {
|
// Hidden on basic receipt — matches t-if="!props.basic_receipt" in order_receipt.xml
|
||||||
|
if (!receiptData.isBasicReceipt && receiptData.paymentData) {
|
||||||
const p = receiptData.paymentData;
|
const p = receiptData.paymentData;
|
||||||
if (p.method) {
|
if (p.method) {
|
||||||
cmds.push(...this.addLine(`Payment: ${p.method}`));
|
cmds.push(...this.addLine(`Payment: ${p.method}`));
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user