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
|
* 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";
|
||||||
@ -33,8 +36,9 @@ patch(OrderSummary.prototype, {
|
|||||||
* 1. Collect the current order's server ID (if it has one) so the server
|
* 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).
|
* can exclude it from its search (it's the empty local order).
|
||||||
* 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();
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user