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";
|
// import { fpRpc } from "../services/fp_rpc";
|
||||||
// await fpRpc("/fp/shopfloor/start_wo", { workorder_id: stepId });
|
// 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";
|
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() {
|
function _getTechStore() {
|
||||||
// Lazy-resolve via the global debug API — avoids circular service init
|
// Lazy-resolve via the global debug API — avoids circular service init
|
||||||
try {
|
try {
|
||||||
@@ -33,10 +60,13 @@ function _getTechStore() {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function fpRpc(url, params = {}) {
|
export async function fpRpc(url, params = {}) {
|
||||||
const techStore = _getTechStore();
|
const mode = await _getSessionMode();
|
||||||
if (techStore && techStore.currentTechId) {
|
if (mode !== "session_swap") {
|
||||||
params = { ...params, tablet_tech_id: techStore.currentTechId };
|
const techStore = _getTechStore();
|
||||||
|
if (techStore && techStore.currentTechId) {
|
||||||
|
params = { ...params, tablet_tech_id: techStore.currentTechId };
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return baseRpc(url, params);
|
return baseRpc(url, params);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user