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.

feat: download csv and json for job bill of material

Brad Barbin22b9a4dcbec6
diff --git a/apps/erp/app/modules/production/ui/Jobs/JobBoMExplorer.tsx b/apps/erp/app/modules/production/ui/Jobs/JobBoMExplorer.tsx
index f0b95f1572..060e7979d7 100644
--- a/apps/erp/app/modules/production/ui/Jobs/JobBoMExplorer.tsx
+++ b/apps/erp/app/modules/production/ui/Jobs/JobBoMExplorer.tsx
@@ -1,6 +1,11 @@
import {
Badge,
Copy,
+ DropdownMenu,
+ DropdownMenuContent,
+ DropdownMenuIcon,
+ DropdownMenuItem,
+ DropdownMenuTrigger,
HStack,
HoverCard,
HoverCardContent,
@@ -16,10 +21,13 @@ import {
import { Link, useFetchers, useNavigate, useParams } from "@remix-run/react";
import { useEffect, useRef, useState } from "react";
import {
+ LuBraces,
LuChevronDown,
LuChevronRight,
+ LuDownload,
LuExternalLink,
LuSearch,
+ LuTable,
} from "react-icons/lu";
import { MethodIcon, MethodItemTypeIcon } from "~/components";
import { OnshapeStatus } from "~/components/Icons";
@@ -41,7 +49,7 @@ const JobBoMExplorer = ({ method }: JobBoMExplorerProps) => {
const navigate = useNavigate();
const location = useOptimisticLocation();
const [filterText, setFilterText] = useState("");
- const { methodId } = useParams();
+ const { jobId, methodId } = useParams();
const fetchers = useFetchers();
const getMethodFetcher = fetchers.find(
@@ -121,6 +129,79 @@ const JobBoMExplorer = ({ method }: JobBoMExplorerProps) => {
onChange={(e) => setFilterText(e.target.value)}
/>
</InputGroup>
+ {jobId && (
+ <DropdownMenu>
+ <DropdownMenuTrigger>
+ <IconButton
+ aria-label="Actions"
+ variant="ghost"
+ icon={<LuDownload />}
+ />
+ </DropdownMenuTrigger>
+ <DropdownMenuContent align="end">
+ <DropdownMenuItem asChild>
+ <a
+ href={path.to.api.jobBillOfMaterialsCsv(jobId, false)}
+ target="_blank"
+ rel="noreferrer"
+ >
+ <DropdownMenuIcon icon={<LuTable />} />
+ <div className="flex flex-grow items-center gap-4 justify-between">
+ <span>BoM</span>
+ <Badge variant="green" className="text-xs">
+ CSV
+ </Badge>
+ </div>
+ </a>
+ </DropdownMenuItem>
+ <DropdownMenuItem asChild>
+ <a
+ href={path.to.api.jobBillOfMaterialsCsv(jobId, true)}
+ target="_blank"
+ rel="noreferrer"
+ >
+ <DropdownMenuIcon icon={<LuTable />} />
+ <div className="flex flex-grow items-center gap-4 justify-between">
+ <span>BoM + BoP</span>
+ <Badge variant="green" className="text-xs">
+ CSV
+ </Badge>
+ </div>
+ </a>
+ </DropdownMenuItem>
+ <DropdownMenuItem asChild>
+ <a
+ href={path.to.api.jobBillOfMaterials(jobId, false)}
+ target="_blank"
+ rel="noreferrer"
+ >
+ <DropdownMenuIcon icon={<LuBraces />} />
+ <div className="flex flex-grow items-center gap-4 justify-between">
+ <span>BoM</span>
+ <Badge variant="outline" className="text-xs">
+ JSON
+ </Badge>
+ </div>
+ </a>
+ </DropdownMenuItem>
+ <DropdownMenuItem asChild>
+ <a
+ href={path.to.api.jobBillOfMaterials(jobId, true)}
+ target="_blank"
+ rel="noreferrer"
+ >
+ <DropdownMenuIcon icon={<LuBraces />} />
+ <div className="flex flex-grow items-center gap-4 justify-between">
+ <span>BoM + BoP</span>
+ <Badge variant="outline" className="text-xs">
+ JSON
+ </Badge>
+ </div>
+ </a>
+ </DropdownMenuItem>
+ </DropdownMenuContent>
+ </DropdownMenu>
+ )}
</HStack>
<TreeView
parentRef={parentRef}
diff --git a/apps/erp/app/routes/api+/items.methods.$id.bom[.]csv.tsx b/apps/erp/app/routes/api+/items.methods.$id.bom[.]csv.tsx
index 1d7ce5b16f..dd315ac100 100644
--- a/apps/erp/app/routes/api+/items.methods.$id.bom[.]csv.tsx
+++ b/apps/erp/app/routes/api+/items.methods.$id.bom[.]csv.tsx
@@ -75,6 +75,8 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
});
}
+ const fileName = `${methodTree.data[0].data.itemReadableId}-bom.csv`;
+
const methods = (
methodTree.data.length > 0 ? flattenTree(methodTree.data[0]) : []
) satisfies FlatTreeItem<Method>[];
@@ -166,7 +168,7 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
return new Response(csv, {
headers: {
"Content-Type": "text/csv",
- "Content-Disposition": "attachment; filename=bom.csv",
+ "Content-Disposition": `attachment; filename=${fileName}`,
},
});
}
diff --git a/apps/erp/app/routes/api+/sales.quote.line.$id.bom[.]csv.tsx b/apps/erp/app/routes/api+/sales.quote.line.$id.bom[.]csv.tsx
index f9a230479f..d6bb6e4f93 100644
--- a/apps/erp/app/routes/api+/sales.quote.line.$id.bom[.]csv.tsx
+++ b/apps/erp/app/routes/api+/sales.quote.line.$id.bom[.]csv.tsx
@@ -56,14 +56,15 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
const quote = await client
.from("quoteLine")
- .select("quoteId, quantity")
+ .select("quoteId, quantity, itemReadableId")
.eq("id", id)
.single();
+ const fileName = `${quote.data?.itemReadableId}-bom.csv`;
if (quote.error) {
return new Response(bomHeaders.join(",") + "\n", {
headers: {
"Content-Type": "text/csv",
- "Content-Disposition": "attachment; filename=bom.csv",
+ "Content-Disposition": `attachment; filename=${fileName}`,
},
});
}
@@ -189,7 +190,7 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
return new Response(csv, {
headers: {
"Content-Type": "text/csv",
- "Content-Disposition": "attachment; filename=bom.csv",
+ "Content-Disposition": `attachment; filename=${fileName}`,
},
});
}
diff --git a/apps/erp/app/utils/bom.ts b/apps/erp/app/utils/bom.ts
index 24a30d4b24..46caa7a896 100644
--- a/apps/erp/app/utils/bom.ts
+++ b/apps/erp/app/utils/bom.ts
@@ -1,10 +1,17 @@
import type { FlatTreeItem } from "~/components/TreeView";
import type { Method } from "~/modules/items";
+import type { JobMethod } from "~/modules/production/types";
import type { QuoteMethod } from "~/modules/sales/types";
export const calculateTotalQuantity = (
- node: FlatTreeItem<QuoteMethod> | FlatTreeItem<Method>,
- nodes: FlatTreeItem<QuoteMethod>[] | FlatTreeItem<Method>[]
+ node:
+ | FlatTreeItem<QuoteMethod>
+ | FlatTreeItem<Method>
+ | FlatTreeItem<JobMethod>,
+ nodes:
+ | FlatTreeItem<QuoteMethod>[]
+ | FlatTreeItem<Method>[]
+ | FlatTreeItem<JobMethod>[]
): number => {
// Create lookup map for faster parent finding
const nodeMap = new Map(nodes.map((n) => [n.id, n]));
@@ -22,7 +29,10 @@ export const calculateTotalQuantity = (
};
export const generateBomIds = (
- nodes: FlatTreeItem<QuoteMethod>[] | FlatTreeItem<Method>[]
+ nodes:
+ | FlatTreeItem<QuoteMethod>[]
+ | FlatTreeItem<Method>[]
+ | FlatTreeItem<JobMethod>[]
): string[] => {
const ids = new Array(nodes.length);
const levelCounters = new Map<number, number>();
diff --git a/apps/erp/app/utils/path.ts b/apps/erp/app/utils/path.ts
index 40e131dbd9..7efdcbb27c 100644
--- a/apps/erp/app/utils/path.ts
+++ b/apps/erp/app/utils/path.ts
@@ -49,6 +49,14 @@ export const path = {
groupsByType: (type?: string) =>
generatePath(`${api}/users/groups?type=${type}`),
item: (type: string) => generatePath(`${api}/item/${type}`),
+ jobBillOfMaterials: (id: string, withOperations: boolean = false) =>
+ generatePath(
+ `${api}/production/methods/${id}/bom?withOperations=${withOperations}`
+ ),
+ jobBillOfMaterialsCsv: (id: string, withOperations: boolean = false) =>
+ generatePath(
+ `${api}/production/methods/${id}/bom.csv?withOperations=${withOperations}`
+ ),
jobs: `${api}/production/jobs`,
locations: `${api}/resources/locations`,
itemPostingGroups: `${api}/items/groups`,