fix: prevent table release on RPC failure to avoid accidental order deletion

This commit is contained in:
Suherdy Yacob 2026-06-15 23:11:28 +07:00
parent bb75a58ca9
commit 881c4af73a

View File

@ -18,6 +18,9 @@
* If the server reports real orders exist, we abort the release, show a * 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 * warning dialog, and refresh the local data so Device Y receives the real
* order from Device X. * 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"; import { patch } from "@web/core/utils/patch";
@ -35,6 +38,7 @@ patch(OrderSummary.prototype, {
* 2. Ask the server: "Does this table have real orders with lines?" * 2. Ask the server: "Does this table have real orders with lines?"
* 3a. Yes warn the user and refresh data. Do NOT delete. * 3a. Yes warn the user and refresh data. Do NOT delete.
* 3b. No proceed with the original unbookTable (safe to release). * 3b. No proceed with the original unbookTable (safe to release).
* 3c. RPC fails block with a warning. Do NOT delete.
*/ */
async unbookTable() { async unbookTable() {
const order = this.pos.getOrder(); const order = this.pos.getOrder();
@ -63,15 +67,17 @@ patch(OrderSummary.prototype, {
[table.id, localOrderIds] [table.id, localOrderIds]
); );
} catch (error) { } catch (error) {
// If the RPC fails (e.g. offline), fall back to the original behaviour. // If the RPC fails (e.g. offline), block the action to prevent accidental deletion.
// This is safer than silently blocking the release when the user is
// genuinely trying to release a truly-empty table while offline.
this.env.services.ui.unblock(); 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( console.warn(
"[pos_ui_optimization] safe_release: RPC failed, falling back to original unbookTable.", "[pos_ui_optimization] safe_release: RPC failed, aborting unbookTable.",
error error
); );
return super.unbookTable(...arguments); return;
} finally { } finally {
this.env.services.ui.unblock(); this.env.services.ui.unblock();
} }