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 => {
|
||||
const name = String(line.productName || '');
|
||||
const qty = line.quantity || 0;
|
||||
const unitPrice = line.price || 0;
|
||||
const total = line.total || 0;
|
||||
const qtyStr = qty % 1 === 0 ? qty.toFixed(0) : qty.toFixed(2);
|
||||
|
||||
// Line 1: product name (truncate to full width)
|
||||
const displayName = name.length > W ? name.substring(0, W - 1) + '.' : name;
|
||||
cmds.push(...this.addLine(displayName, { bold: false }));
|
||||
if (receiptData.isBasicReceipt) {
|
||||
// ── Basic receipt / table checker ──────────────────────────
|
||||
// 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)
|
||||
const priceStr = this.formatAmount(unitPrice);
|
||||
const totalStr = this.formatAmount(total);
|
||||
const qtyStr = `${qty % 1 === 0 ? qty.toFixed(0) : qty.toFixed(2)}x`;
|
||||
// Build: " 2x 14.985.000 29.970.000"
|
||||
const middle = `${qtyStr} ${priceStr}`;
|
||||
let itemLine = middle + totalStr.padStart(W - middle.length);
|
||||
if (itemLine.length > W) {
|
||||
// fallback: just right-align total
|
||||
itemLine = totalStr.padStart(W);
|
||||
// Line 2: qty x unitPrice = total (right-aligned)
|
||||
const priceStr = this.formatAmount(line.price || 0);
|
||||
const totalStr = this.formatAmount(line.total || 0);
|
||||
const middle = `${qtyStr}x ${priceStr}`;
|
||||
let itemLine = middle + totalStr.padStart(W - middle.length);
|
||||
if (itemLine.length > W) itemLine = totalStr.padStart(W);
|
||||
cmds.push(...this.addLine(itemLine));
|
||||
}
|
||||
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) {
|
||||
const noteText = `* ${line.note}`;
|
||||
cmds.push(...this.addLine(
|
||||
@ -273,7 +281,8 @@ export class EscPosGenerator {
|
||||
}
|
||||
|
||||
// ── 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;
|
||||
|
||||
if (t.subtotal !== undefined) {
|
||||
@ -298,7 +307,8 @@ export class EscPosGenerator {
|
||||
}
|
||||
|
||||
// ── 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;
|
||||
if (p.method) {
|
||||
cmds.push(...this.addLine(`Payment: ${p.method}`));
|
||||
|
||||
Loading…
Reference in New Issue
Block a user