Skip to content

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.

fix: subassembly files

Sidwebworksbab4d65896f6
diff --git a/apps/mes/app/components/JobOperation/hooks/useFiles.tsx b/apps/mes/app/components/JobOperation/hooks/useFiles.tsx
index e9b2bdfd95..91052f5e4a 100644
--- a/apps/mes/app/components/JobOperation/hooks/useFiles.tsx
+++ b/apps/mes/app/components/JobOperation/hooks/useFiles.tsx
@@ -21,7 +21,7 @@ export function useFiles(job: Job) {
id = job.salesOrderLineId ?? job.quoteLineId;
break;
case "parts":
- id = job.itemId;
+ id = file.itemId ?? job.itemId;
break;
}
diff --git a/apps/mes/app/services/operations.service.ts b/apps/mes/app/services/operations.service.ts
index 80b22364dc..dac00bcde3 100644
--- a/apps/mes/app/services/operations.service.ts
+++ b/apps/mes/app/services/operations.service.ts
@@ -196,13 +196,21 @@ const getItemFiles = async (
companyId: string,
items: Array<{ itemId: string }>
) => {
- const elems = items.map((el) =>
- client.storage.from("private").list(`${companyId}/parts/${el.itemId}`)
- );
+ const getFile = async (id: string) => {
+ const res = await client.storage
+ .from("private")
+ .list(`${companyId}/parts/${id}`);
+
+ if (res.error || !res.data) return null;
+
+ return res.data.map((f) => ({ ...f, bucket: "parts", itemId: id }));
+ };
+
+ const elems = items.map((el) => getFile(el.itemId));
const results = await Promise.all(elems);
- return results.flatMap((res) => res.data ?? []);
+ return results.filter((f) => f !== null).flat();
};
export async function getJobFiles(
@@ -229,7 +237,7 @@ export async function getJobFiles(
bucket: "opportunity-line"
})) || []),
...(jobFiles.data?.map((f) => ({ ...f, bucket: "job" })) || []),
- ...(itemFiles.map((f) => ({ ...f, bucket: "parts" })) || [])
+ ...itemFiles
];
} else {
const [jobFiles, itemFiles] = await Promise.all([
@@ -239,7 +247,7 @@ export async function getJobFiles(
return [
...(jobFiles.data?.map((f) => ({ ...f, bucket: "job" })) || []),
- ...(itemFiles.map((f) => ({ ...f, bucket: "parts" })) || [])
+ ...itemFiles
];
}
}
diff --git a/apps/mes/app/services/types.ts b/apps/mes/app/services/types.ts
index 7495054b57..82bd18a61c 100644
--- a/apps/mes/app/services/types.ts
+++ b/apps/mes/app/services/types.ts
@@ -83,6 +83,7 @@ export type ProductionQuantity = NonNullable<
export type StorageItem = FileObject & {
bucket: string;
+ itemId?: string;
};
export type TrackedEntity = NonNullable<