fix: prevent table release on RPC failure to avoid accidental order deletion
This commit is contained in:
parent
bb75a58ca9
commit
881c4af73a
@ -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";
|
||||
@ -35,6 +38,7 @@ patch(OrderSummary.prototype, {
|
||||
* 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).
|
||||
* 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();
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user