From 6d4b6284adf8b42ea93823c5c51f886f6ddc0a92 Mon Sep 17 00:00:00 2001 From: gsinghpal Date: Sun, 24 May 2026 13:18:33 -0400 Subject: [PATCH] feat(shopfloor): fpRpc skips tablet_tech_id injection in session_swap mode MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When tablet_session_mode='session_swap', the server attributes every write via request.env.user — there's no need to pass tablet_tech_id in the RPC params. Caches the mode lookup at module level so we don't round-trip on every RPC. Legacy mode unchanged — fpRpc still injects tablet_tech_id from techStore.currentTechId. Co-Authored-By: Claude Opus 4.7 (1M context) --- .../static/src/js/services/fp_rpc.js | 38 +++++++++++++++++-- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/fusion_plating/fusion_plating_shopfloor/static/src/js/services/fp_rpc.js b/fusion_plating/fusion_plating_shopfloor/static/src/js/services/fp_rpc.js index 82c9e890..1be24120 100644 --- a/fusion_plating/fusion_plating_shopfloor/static/src/js/services/fp_rpc.js +++ b/fusion_plating/fusion_plating_shopfloor/static/src/js/services/fp_rpc.js @@ -16,10 +16,37 @@ // import { fpRpc } from "../services/fp_rpc"; // await fpRpc("/fp/shopfloor/start_wo", { workorder_id: stepId }); // +// Phase D — in `session_swap` mode, the tablet operates on a REAL Odoo +// session minted by /fp/tablet/unlock_session whose uid IS the tech. +// In that mode tablet_tech_id is redundant; the server attributes the +// write to request.env.user directly. We cache the mode at module +// level (refresh on every page load, exactly when the session may +// have flipped). // ============================================================================= import { rpc as baseRpc } from "@web/core/network/rpc"; +let _sessionModeCache = null; // 'legacy' | 'session_swap' | null (unknown) + +async function _getSessionMode() { + if (_sessionModeCache !== null) return _sessionModeCache; + try { + const res = await baseRpc("/web/dataset/call_kw", { + model: "ir.config_parameter", + method: "get_param", + args: ["fp.shopfloor.tablet_session_mode", "legacy"], + kwargs: {}, + }); + _sessionModeCache = res || "legacy"; + } catch (e) { + // If the lookup fails (network blip, ACL change), fail SAFE + // to legacy — that keeps tablet_tech_id injection on so the + // server-side audit attribution still works. + _sessionModeCache = "legacy"; + } + return _sessionModeCache; +} + function _getTechStore() { // Lazy-resolve via the global debug API — avoids circular service init try { @@ -33,10 +60,13 @@ function _getTechStore() { return null; } -export function fpRpc(url, params = {}) { - const techStore = _getTechStore(); - if (techStore && techStore.currentTechId) { - params = { ...params, tablet_tech_id: techStore.currentTechId }; +export async function fpRpc(url, params = {}) { + const mode = await _getSessionMode(); + if (mode !== "session_swap") { + const techStore = _getTechStore(); + if (techStore && techStore.currentTechId) { + params = { ...params, tablet_tech_id: techStore.currentTechId }; + } } return baseRpc(url, params); }