fix: ensure consistent receipt data parsing and include order notes in all print modes

This commit is contained in:
Suherdy Yacob 2026-06-03 15:41:24 +07:00
parent fa2f72cf61
commit ac9b328e51

View File

@ -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