From ac9b328e51ee4348537cbafb732daef2e5f575ec Mon Sep 17 00:00:00 2001 From: Suherdy Yacob Date: Wed, 3 Jun 2026 15:41:24 +0700 Subject: [PATCH] fix: ensure consistent receipt data parsing and include order notes in all print modes --- static/src/js/pos_receipt_printer.js | 42 +++++++++++++++------------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/static/src/js/pos_receipt_printer.js b/static/src/js/pos_receipt_printer.js index ea925b6..b9343b0 100755 --- a/static/src/js/pos_receipt_printer.js +++ b/static/src/js/pos_receipt_printer.js @@ -123,6 +123,13 @@ patch(PosPrinterService.prototype, { } } + if (order) { + this._currentPrintOrder = order; + } + if (printType === 'CHECKER') { + this._currentPrintBasic = true; + } + this._isCashPayment = printType === 'PAYMENT' && order && (typeof order.isPaidWithCash === 'function' ? order.isPaidWithCash() : false); console.log(`[BluetoothPrint] printHtml context check - printType: ${printType}, order: ${order?.pos_reference}, resolved isCashPayment: ${this._isCashPayment}`); @@ -552,13 +559,12 @@ patch(PosPrinterService.prototype, { // Prefer direct model data over HTML parsing — HTML parsing fails in basic_receipt mode // because prices and totals are not rendered in the DOM when basic_receipt=true. let receiptData; - const isKitchenReceipt = !!el.querySelector('.new-changes, .preset-name, .o-employee-name, .order-ref-prefix'); - if (this._currentPrintOrder && !isKitchenReceipt) { + if (this._currentPrintOrder) { console.log('[BluetoothPrint] Building receipt data from POS order model (accurate)...'); receiptData = this._buildReceiptDataFromOrder(this._currentPrintOrder); } else { - console.log('[BluetoothPrint] Kitchen receipt or no order captured, parsing HTML...'); + console.log('[BluetoothPrint] No order captured, parsing HTML...'); receiptData = this._parseReceiptDataFromHtml(el); } console.log('[BluetoothPrint] Receipt data:', JSON.stringify(receiptData, null, 2)); @@ -794,8 +800,8 @@ patch(PosPrinterService.prototype, { cashier: formatFirstLastName((typeof order.getCashierName === 'function' ? order.getCashierName() : '') || ''), customer: order.partner_id?.name || null, tableName, - internalNote: isBasic ? (pos?.getStrNotes ? pos.getStrNotes(order.internal_note || '[]') : (typeof order.internal_note === 'string' ? order.internal_note : '')) : '', - customerNote: isBasic ? (order.general_customer_note || '') : '', + internalNote: pos?.getStrNotes ? pos.getStrNotes(order.internal_note || '[]') : (typeof order.internal_note === 'string' ? order.internal_note : ''), + customerNote: order.general_customer_note || '', }; // ── Order lines ──────────────────────────────────────────────────────── @@ -826,22 +832,20 @@ patch(PosPrinterService.prototype, { ? line.displayPriceUnit : (qty !== 0 ? lineTotal / qty : line.price_unit || 0); - // Construct combined line note if basic receipt, else empty string + // Construct combined line note let note = ''; - if (isBasic) { - const noteParts = []; - const customerNote = line.customer_note || line.customerNote || ''; - if (customerNote) { - noteParts.push(customerNote); - } - if (line.note) { - const internalNote = pos?.getStrNotes ? pos.getStrNotes(line.note) : (typeof line.note === 'string' ? line.note : ''); - if (internalNote) { - noteParts.push(internalNote); - } - } - note = noteParts.join(' | '); + const noteParts = []; + const customerNote = line.customer_note || line.customerNote || ''; + if (customerNote) { + noteParts.push(customerNote); } + if (line.note) { + const internalNote = pos?.getStrNotes ? pos.getStrNotes(line.note) : (typeof line.note === 'string' ? line.note : ''); + if (internalNote) { + noteParts.push(internalNote); + } + } + note = noteParts.join(' | '); // Find combo sub-lines linked to this line const comboSubLines = orderlines