feat(shopfloor): fpRpc skips tablet_tech_id injection in session_swap mode
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) <noreply@anthropic.com>
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user