From 881c4af73a0337751a405ab7392f3d04d1abd51b Mon Sep 17 00:00:00 2001 From: Suherdy Yacob Date: Mon, 15 Jun 2026 23:11:28 +0700 Subject: [PATCH] fix: prevent table release on RPC failure to avoid accidental order deletion --- .../order_summary/safe_release_patch.js | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/static/src/app/screens/product_screen/order_summary/safe_release_patch.js b/static/src/app/screens/product_screen/order_summary/safe_release_patch.js index 6a5d4b6..3695db2 100644 --- a/static/src/app/screens/product_screen/order_summary/safe_release_patch.js +++ b/static/src/app/screens/product_screen/order_summary/safe_release_patch.js @@ -18,6 +18,9 @@ * If the server reports real orders exist, we abort the release, show a * warning dialog, and refresh the local data so Device Y receives the real * order from Device X. + * If the server check fails (offline/timeout), we BLOCK the release rather + * than falling through, since proceeding when the server is unreachable + * risks cancelling another device's real order. */ import { patch } from "@web/core/utils/patch"; @@ -33,8 +36,9 @@ patch(OrderSummary.prototype, { * 1. Collect the current order's server ID (if it has one) so the server * can exclude it from its search (it's the empty local order). * 2. Ask the server: "Does this table have real orders with lines?" - * 3a. Yes → warn the user and refresh data. Do NOT delete. - * 3b. No → proceed with the original unbookTable (safe to release). + * 3a. Yes → warn the user and refresh data. Do NOT delete. + * 3b. No → proceed with the original unbookTable (safe to release). + * 3c. RPC fails → block with a warning. Do NOT delete. */ async unbookTable() { const order = this.pos.getOrder(); @@ -63,15 +67,17 @@ patch(OrderSummary.prototype, { [table.id, localOrderIds] ); } catch (error) { - // If the RPC fails (e.g. offline), fall back to the original behaviour. - // This is safer than silently blocking the release when the user is - // genuinely trying to release a truly-empty table while offline. + // If the RPC fails (e.g. offline), block the action to prevent accidental deletion. this.env.services.ui.unblock(); + this.env.services.dialog.add(AlertDialog, { + title: _t("Connection Error"), + body: _t("Could not verify table status. Please check your connection and try again."), + }); console.warn( - "[pos_ui_optimization] safe_release: RPC failed, falling back to original unbookTable.", + "[pos_ui_optimization] safe_release: RPC failed, aborting unbookTable.", error ); - return super.unbookTable(...arguments); + return; } finally { this.env.services.ui.unblock(); }