From 16b7a317f8caa585cea1c9e201550c1fd3ed31c8 Mon Sep 17 00:00:00 2001 From: Suherdy Yacob Date: Sat, 20 Jun 2026 09:54:46 +0700 Subject: [PATCH] feat: extend floor screen sync to product screen and increase refresh frequency to 5 seconds --- .../floor_screen/floor_screen_sync_patch.js | 29 +++++++++++++++++-- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/static/src/app/screens/floor_screen/floor_screen_sync_patch.js b/static/src/app/screens/floor_screen/floor_screen_sync_patch.js index 62c2fa9..ba62aea 100644 --- a/static/src/app/screens/floor_screen/floor_screen_sync_patch.js +++ b/static/src/app/screens/floor_screen/floor_screen_sync_patch.js @@ -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(); + }); + }, +});