feat: add automatic cash drawer triggers for opening and closing popups and enforce explicit action strings for all manual cashbox requests

This commit is contained in:
Suherdy Yacob 2026-06-17 22:08:05 +07:00
parent 85692e2fec
commit 3fbccec8e3

View File

@ -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 OrderPaymentValidation from "@point_of_sale/app/utils/order_payment_validation";
import { patch } from "@web/core/utils/patch"; import { patch } from "@web/core/utils/patch";
import { getBluetoothPrintingServices } from "./pos_receipt_printer"; 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 to track validation context
patch(OrderPaymentValidation.prototype, { patch(OrderPaymentValidation.prototype, {
@ -93,10 +132,10 @@ patch(HardwareProxy.prototype, {
console.log(`[CashDrawer] Blocking — print context: printType=${printType}, cash=${order?.isPaidWithCash()}`); 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 { else {
console.log("[CashDrawer] No context — allowing as manual trigger."); console.log("[CashDrawer] No context — BLOCKING! Manual triggers must provide an action string.");
allowOpen = true; allowOpen = false;
} }
if (allowOpen) { if (allowOpen) {