Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.
TypeScript ai-agentsbill-of-materialserpinventory-managementleanmanufacturingmanufacturing-execution-systemmcp-servermesmrpopen-source-erppostgresqlproduction-planningqmsquality-management-systemreact-routerself-hostedsupabasetraceabilitytypescript
fix(assembly): step path saves are company-scoped, and Reset is not undone by a pending drag save
aashuccebc75f6808
diff --git a/apps/erp/app/modules/production/production.service.ts b/apps/erp/app/modules/production/production.service.tsindex 5c08fe7e04..38a4488e45 100644--- a/apps/erp/app/modules/production/production.service.ts+++ b/apps/erp/app/modules/production/production.service.ts@@ -7884,6 +7884,7 @@ export async function updateAssemblyStepMotion(camera?: z.infer<typeof cameraSchema> | null;/** Put back the motion the step had before its path was first drawn. */reset?: boolean;+ companyId: string;updatedBy: string;}) {@@ -7893,6 +7894,7 @@ export async function updateAssemblyStepMotion(.from("assemblyInstructionStep").select("motion, warnings").eq("id", data.id)+ .eq("companyId", data.companyId).single();if (current.error) return { data: null, error: current.error };// The first hand-drawn edit keeps the planner's motion in@@ -7934,6 +7936,7 @@ export async function updateAssemblyStepMotion(updatedAt: new Date().toISOString()}).eq("id", data.id)+ .eq("companyId", data.companyId).select("id").single();}diff --git a/apps/erp/app/routes/x+/assembly+/$id.steps.motion.$stepId.tsx b/apps/erp/app/routes/x+/assembly+/$id.steps.motion.$stepId.tsxindex 8b1b438620..c263314e06 100644--- a/apps/erp/app/routes/x+/assembly+/$id.steps.motion.$stepId.tsx+++ b/apps/erp/app/routes/x+/assembly+/$id.steps.motion.$stepId.tsx@@ -21,7 +21,7 @@ import {// a step (drag autosave + "Set view"/"Clear view"), leaving the rest untouched.export async function action({ request, params }: ActionFunctionArgs) {assertIsPost(request);- const { client, userId } = await requirePermissions(request, {+ const { client, companyId, userId } = await requirePermissions(request, {update: "production"});@@ -49,6 +49,7 @@ export async function action({ request, params }: ActionFunctionArgs) {motion: validation.data.motion,camera: validation.data.camera,reset: validation.data.reset,+ companyId,updatedBy: userId});logAssemblyStep("motion.updateResult", {diff --git a/apps/erp/app/routes/x+/assembly+/$id.tsx b/apps/erp/app/routes/x+/assembly+/$id.tsxindex c5ceee8db9..86723b6000 100644--- a/apps/erp/app/routes/x+/assembly+/$id.tsx+++ b/apps/erp/app/routes/x+/assembly+/$id.tsx@@ -628,6 +628,9 @@ export default function AssemblyInstructionRoute() {const [editingUnitId, setEditingUnitId] = useState<string | null>(null);const [draftMotion, setDraftMotion] = useState<Motion | null>(null);const saveTimer = useRef<ReturnType<typeof setTimeout> | null>(null);+ const pendingMotion = useRef<{ targetId: string; motion: Motion } | null>(+ null+ );const saveMotion = useCallback((@@ -650,40 +653,58 @@ export default function AssemblyInstructionRoute() {[motionFetcher, id]);+ // The drag autosave waits 400 ms; leaving or switching an edit sends it now.+ const flushMotionSave = useCallback(() => {+ if (saveTimer.current) clearTimeout(saveTimer.current);+ saveTimer.current = null;+ const pending = pendingMotion.current;+ pendingMotion.current = null;+ if (pending) saveMotion(pending.targetId, { motion: pending.motion });+ }, [saveMotion]);+const onEditMotion = useCallback((stepId: string, unitHeaderId?: string) => {+ flushMotionSave();const edited = viewerSteps.find((s) => s.id === (unitHeaderId ?? stepId));setSelectedStepId(stepId);setEditingStepId(stepId);setEditingUnitId(unitHeaderId ?? null);setDraftMotion(edited?.motion ?? { type: "none" });},- [viewerSteps]+ [viewerSteps, flushMotionSave]);const onStopEditMotion = useCallback(() => {+ flushMotionSave();setEditingStepId(null);setEditingUnitId(null);setDraftMotion(null);- }, []);+ }, [flushMotionSave]);const onMotionChange = useCallback((stepId: string, motion: Motion) => {setDraftMotion(motion);// A sub-assembly's path lives on its header row.- const targetId = editingUnitId ?? stepId;+ pendingMotion.current = { targetId: editingUnitId ?? stepId, motion };if (saveTimer.current) clearTimeout(saveTimer.current);- saveTimer.current = setTimeout(- () => saveMotion(targetId, { motion }),- 400- );+ saveTimer.current = setTimeout(flushMotionSave, 400);},- [saveMotion, editingUnitId]+ [flushMotionSave, editingUnitId]);const onResetMotion = useCallback(- (stepId: string) => saveMotion(stepId, { reset: true }),- [saveMotion]+ (stepId: string) => {+ // A drag still waiting to save on this row must not land after the reset.+ if (pendingMotion.current?.targetId === stepId) {+ if (saveTimer.current) clearTimeout(saveTimer.current);+ saveTimer.current = null;+ pendingMotion.current = null;+ } else {+ flushMotionSave();+ }+ saveMotion(stepId, { reset: true });+ },+ [saveMotion, flushMotionSave]);const onSetCamera = useCallback(