feat: extend floor screen sync to product screen and increase refresh frequency to 5 seconds

This commit is contained in:
Suherdy Yacob 2026-06-20 09:54:46 +07:00
parent 5c9296a150
commit 16b7a317f8

View File

@ -52,12 +52,14 @@
*/
import { FloorScreen } from "@pos_restaurant/app/screens/floor_screen/floor_screen";
import { ProductScreen } from "@point_of_sale/app/screens/product_screen/product_screen";
import { PosStore } from "@point_of_sale/app/services/pos_store";
import { patch } from "@web/core/utils/patch";
import { onMounted, onWillUnmount } from "@odoo/owl";
// Auto-refresh interval (avoid numeric separators for WebView < 75 compat)
const AUTO_REFRESH_INTERVAL_MS = 30000;
// Reduced to 5 seconds to minimize data collision during active multi-device use on the same table.
const AUTO_REFRESH_INTERVAL_MS = 5000;
// ─── PosStore patch ───────────────────────────────────────────────────────────
patch(PosStore.prototype, {
@ -66,6 +68,7 @@ patch(PosStore.prototype, {
* Guards against double-initialisation (e.g. if FloorScreen unmounts/remounts).
*/
setupSyncRefresh() {
this._syncRefreshRefs = (this._syncRefreshRefs || 0) + 1;
if (this._syncRefreshInitialized) {
return;
}
@ -104,6 +107,11 @@ patch(PosStore.prototype, {
* Remove all timers and event listeners. Called from FloorScreen.onWillUnmount.
*/
destroySyncRefresh() {
this._syncRefreshRefs = Math.max(0, (this._syncRefreshRefs || 0) - 1);
if (this._syncRefreshRefs > 0) {
return; // Keep running if another screen still needs it
}
if (this._autoRefreshInterval) {
clearInterval(this._autoRefreshInterval);
this._autoRefreshInterval = null;
@ -142,9 +150,9 @@ patch(PosStore.prototype, {
return;
}
// Guard 3: only on FloorScreen
// Guard 3: only on FloorScreen or ProductScreen
const screenName = this.router?.state?.current;
if (!screenName || screenName !== "FloorScreen") {
if (!screenName || !["FloorScreen", "ProductScreen"].includes(screenName)) {
return;
}
@ -208,3 +216,18 @@ patch(FloorScreen.prototype, {
return super.onClickTable(table, ev);
},
});
// ─── ProductScreen patch ──────────────────────────────────────────────────────
patch(ProductScreen.prototype, {
setup() {
super.setup(...arguments);
onMounted(() => {
this.pos.setupSyncRefresh();
});
onWillUnmount(() => {
this.pos.destroySyncRefresh();
});
},
});