From 527b0f63bf2c92337d8bbd7ce4d492815e380798 Mon Sep 17 00:00:00 2001 From: Suherdy Yacob Date: Fri, 5 Jun 2026 09:28:38 +0700 Subject: [PATCH] refactor: replace Odoo printer service with direct window-based HTML rendering for closing receipts --- static/src/app/closing_receipt.css | 12 --- static/src/app/closing_receipt_patch.js | 138 ++++++++++++++++++++++-- 2 files changed, 128 insertions(+), 22 deletions(-) diff --git a/static/src/app/closing_receipt.css b/static/src/app/closing_receipt.css index 176e052..28dbaeb 100644 --- a/static/src/app/closing_receipt.css +++ b/static/src/app/closing_receipt.css @@ -21,23 +21,11 @@ border: 0 !important; } - .pos-closing-receipt-print { - width: 100% !important; - } - .pos-closing-receipt-print .pos-receipt { padding-left: 20px !important; padding-right: 20px !important; box-sizing: border-box !important; } - - .render-container .pos-closing-receipt-print .pos-receipt { - font-size: 28px !important; - width: 320px !important; - max-width: 320px !important; - padding: 12px !important; - margin: 0 auto !important; - } } diff --git a/static/src/app/closing_receipt_patch.js b/static/src/app/closing_receipt_patch.js index 5c26b7b..7f2d189 100644 --- a/static/src/app/closing_receipt_patch.js +++ b/static/src/app/closing_receipt_patch.js @@ -165,16 +165,134 @@ patch(ClosePosPopup.prototype, { this.pos.env.services.ui.block(); } try { - const printResult = await this.printer.print(ClosingReceipt, receiptData, { - webPrintFallback: true, - }); - console.log("[pos_closing_receipt] Print operation resolved with result:", printResult); - - // Explicit safety delay to let printer buffers flush (especially for Bluetooth/JSPM) - const delayMs = 1500; - console.log(`[pos_closing_receipt] Applying safety buffer delay of ${delayMs}ms...`); - await new Promise((resolve) => setTimeout(resolve, delayMs)); - console.log("[pos_closing_receipt] Safety buffer complete."); + let cashRow = ""; + if (receiptData.cashPayment) { + cashRow = ` + + ${receiptData.cashPayment.name} + ${receiptData.cashPayment.formattedAmount} + `; + } + + const nonCashRows = (receiptData.nonCashPayments || []).map( + (pm) => ` + + ${pm.name} + ${pm.formattedAmount} + ` + ); + + const html = ` + + + + Closing Summary + + + +
+
+
${receiptData.sessionName}
+
SESSION CLOSING SUMMARY
+
+
+ + + + + + + + + +
Cashier${receiptData.cashierName}
Date/Time${receiptData.closingTime}
+
+ + ${cashRow} + ${nonCashRows.join("")} +
+
+ + + + + +
TOTAL${receiptData.grandTotal}
+
+ +
 
+
+ + +`; + + const printWindow = window.open("", "_blank", "width=400,height=600"); + if (!printWindow) { + const notification = this.pos?.env?.services?.notification; + if (notification) { + notification.add( + _t("Pop-up blocked. Please allow pop-ups for this site and try again to print closing receipt."), + { type: "warning" } + ); + } else { + alert("Pop-up blocked. Please allow pop-ups for this site and try again to print closing receipt."); + } + return; + } + printWindow.document.open(); + printWindow.document.write(html); + printWindow.document.close(); + + // Safety delay to allow window to open and print dialog to spawn before proceeding + await new Promise((resolve) => setTimeout(resolve, 1500)); } catch (err) { console.error("[pos_closing_receipt] CRITICAL: Failed to print closing receipt:", err); } finally {