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
* 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();
}