From 3fbccec8e3e1dc5ba368e0113d5eeb9952e6e816 Mon Sep 17 00:00:00 2001 From: Suherdy Yacob Date: Wed, 17 Jun 2026 22:08:05 +0700 Subject: [PATCH] feat: add automatic cash drawer triggers for opening and closing popups and enforce explicit action strings for all manual cashbox requests --- static/src/js/pos_hardware_proxy_patch.js | 45 +++++++++++++++++++++-- 1 file changed, 42 insertions(+), 3 deletions(-) diff --git a/static/src/js/pos_hardware_proxy_patch.js b/static/src/js/pos_hardware_proxy_patch.js index 2206b61..ec7e6de 100644 --- a/static/src/js/pos_hardware_proxy_patch.js +++ b/static/src/js/pos_hardware_proxy_patch.js @@ -5,6 +5,45 @@ import { PosStore } from "@point_of_sale/app/services/pos_store"; import OrderPaymentValidation from "@point_of_sale/app/utils/order_payment_validation"; import { patch } from "@web/core/utils/patch"; import { getBluetoothPrintingServices } from "./pos_receipt_printer"; +import { PaymentScreen } from "@point_of_sale/app/screens/payment_screen/payment_screen"; +import { OpeningControlPopup } from "@point_of_sale/app/components/popups/opening_control_popup/opening_control_popup"; +import { ClosingPopup } from "@point_of_sale/app/components/popups/closing_popup/closing_popup"; +import { onMounted } from "@odoo/owl"; + +// Patch OpeningControlPopup to open cash drawer automatically upon loading +patch(OpeningControlPopup.prototype, { + setup() { + super.setup(...arguments); + onMounted(() => { + if (this.hardwareProxy) { + this.hardwareProxy.openCashbox('OpeningControl_Auto'); + } + }); + } +}); + +// Patch ClosingPopup to open cash drawer automatically upon loading +patch(ClosingPopup.prototype, { + setup() { + super.setup(...arguments); + onMounted(() => { + if (this.hardwareProxy) { + this.hardwareProxy.openCashbox('ClosingControl_Auto'); + } + }); + } +}); + +// Patch PaymentScreen to explicitly mark manual cashbox opens +patch(PaymentScreen.prototype, { + openCashbox() { + if (this.hardwareProxy) { + this.hardwareProxy.openCashbox('PaymentScreen_Manual'); + } else { + super.openCashbox(...arguments); + } + } +}); // Patch OrderPaymentValidation to track validation context patch(OrderPaymentValidation.prototype, { @@ -93,10 +132,10 @@ patch(HardwareProxy.prototype, { console.log(`[CashDrawer] Blocking — print context: printType=${printType}, cash=${order?.isPaidWithCash()}`); } } - // (B) No context at all — manual button (e.g. payment screen Open Cashbox button) + // (B) No context at all — strictly block to prevent rogue triggers else { - console.log("[CashDrawer] No context — allowing as manual trigger."); - allowOpen = true; + console.log("[CashDrawer] No context — BLOCKING! Manual triggers must provide an action string."); + allowOpen = false; } if (allowOpen) {