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
feat: copy granular parts with get method
Brad Barbincb35f9e7916c
diff --git a/apps/erp/app/modules/items/items.models.ts b/apps/erp/app/modules/items/items.models.tsindex ec838e0a5a..fe96fcf087 100644--- a/apps/erp/app/modules/items/items.models.ts+++ b/apps/erp/app/modules/items/items.models.ts@@ -156,7 +156,13 @@ export const customerPartValidator = z.object({export const getMethodValidator = z.object({targetId: z.string().min(1, { message: "Please select a target method" }),- sourceId: z.string().min(1, { message: "Please select a source method" })+ sourceId: z.string().min(1, { message: "Please select a source method" }),+ billOfMaterial: zfd.checkbox(),+ billOfProcess: zfd.checkbox(),+ parameters: zfd.checkbox(),+ tools: zfd.checkbox(),+ steps: zfd.checkbox(),+ workInstructions: zfd.checkbox()});export const makeMethodVersionValidator = z.object({diff --git a/apps/erp/app/modules/items/items.service.ts b/apps/erp/app/modules/items/items.service.tsindex 2914eaa21d..3a10d7deb4 100644--- a/apps/erp/app/modules/items/items.service.ts+++ b/apps/erp/app/modules/items/items.service.ts@@ -77,7 +77,15 @@ export async function copyItem(sourceId: args.sourceId,targetId: args.targetId,companyId: args.companyId,- userId: args.userId+ userId: args.userId,+ parts: {+ billOfMaterial: args.billOfMaterial,+ billOfProcess: args.billOfProcess,+ parameters: args.parameters,+ tools: args.tools,+ steps: args.steps,+ workInstructions: args.workInstructions+ }},region: FunctionRegion.UsEast1});diff --git a/apps/erp/app/modules/items/ui/Item/BillOfProcess.tsx b/apps/erp/app/modules/items/ui/Item/BillOfProcess.tsxindex 2b7c098cfa..c0906969e1 100644--- a/apps/erp/app/modules/items/ui/Item/BillOfProcess.tsx+++ b/apps/erp/app/modules/items/ui/Item/BillOfProcess.tsx@@ -2700,7 +2700,7 @@ function ToolsForm({return (<div className="flex flex-col gap-6">{!isDisabled && (- <div className="p-6 border rounded-lg">+ <div className="p-6 border rounded-lg bg-card"><ValidatedFormaction={path.to.newMethodOperationTool}method="post"@@ -2794,7 +2794,7 @@ function ToolsListItem({const date = updatedAt ?? createdAt;return (- <div className={cn("border-b p-6", className)}>+ <div className={cn("border-b p-6 bg-card", className)}>{disclosure.isOpen ? (<ValidatedFormaction={path.to.methodOperationTool(id)}diff --git a/apps/erp/app/modules/items/ui/Item/MakeMethodTools.tsx b/apps/erp/app/modules/items/ui/Item/MakeMethodTools.tsxindex bac6be2c3d..cc2d608c7d 100644--- a/apps/erp/app/modules/items/ui/Item/MakeMethodTools.tsx+++ b/apps/erp/app/modules/items/ui/Item/MakeMethodTools.tsx@@ -6,6 +6,9 @@ import {Badge,Button,Checkbox,+ Collapsible,+ CollapsibleContent,+ CollapsibleTrigger,cn,DropdownMenu,DropdownMenuContent,@@ -36,6 +39,7 @@ import { flushSync } from "react-dom";import {LuCheck,LuChevronDown,+ LuChevronRight,LuCirclePlus,LuCopy,LuGitBranch,@@ -294,6 +298,7 @@ const MakeMethodTools = ({This will overwrite the existing manufacturing method</AlertTitle></Alert>+ <AdvancedSection /></VStack></ModalBody><ModalFooter>@@ -356,6 +361,7 @@ const MakeMethodTools = ({Include Inactive</label></div>+ <AdvancedSection /></VStack></ModalBody><ModalFooter>@@ -453,4 +459,96 @@ const MakeMethodTools = ({);};+function AdvancedSection() {+ const [open, setOpen] = useState(false);+ const [billOfProcess, setBillOfProcess] = useState(true);+ const [parameters, setParameters] = useState(true);+ const [tools, setTools] = useState(true);+ const [steps, setSteps] = useState(true);+ const [workInstructions, setWorkInstructions] = useState(true);++ const processChildren = [+ {+ name: "parameters",+ label: "Parameters",+ checked: parameters,+ onChange: setParameters+ },+ { name: "tools", label: "Tools", checked: tools, onChange: setTools },+ { name: "steps", label: "Steps", checked: steps, onChange: setSteps },+ {+ name: "workInstructions",+ label: "Work Instructions",+ checked: workInstructions,+ onChange: setWorkInstructions+ }+ ];++ return (+ <Collapsible className="w-full" open={open} onOpenChange={setOpen}>+ <CollapsibleTrigger asChild>+ <Button variant="ghost" className="w-full justify-start gap-2 px-0">+ <LuChevronRight+ className={cn("h-4 w-4 transition-transform", open && "rotate-90")}+ />+ Advanced+ </Button>+ </CollapsibleTrigger>+ <CollapsibleContent forceMount className={cn(!open && "hidden")}>+ <VStack spacing={2} className="pt-2">+ <div className="flex items-center space-x-2">+ <Checkbox+ id="billOfMaterial"+ name="billOfMaterial"+ defaultChecked+ />+ <label+ htmlFor="billOfMaterial"+ className="text-sm font-medium leading-none"+ >+ Bill of Material+ </label>+ </div>+ <div className="flex items-center space-x-2">+ <Checkbox+ id="billOfProcess"+ name="billOfProcess"+ checked={billOfProcess}+ onCheckedChange={(checked) => setBillOfProcess(!!checked)}+ />+ <label+ htmlFor="billOfProcess"+ className="text-sm font-medium leading-none"+ >+ Bill of Process+ </label>+ </div>+ <VStack spacing={2} className="pl-6">+ {processChildren.map(({ name, label, checked, onChange }) => (+ <div key={name} className="flex items-center space-x-2">+ <Checkbox+ id={name}+ name={name}+ disabled={!billOfProcess}+ checked={billOfProcess ? checked : false}+ onCheckedChange={(val) => onChange(!!val)}+ />+ <label+ htmlFor={name}+ className={cn(+ "text-sm font-medium leading-none",+ !billOfProcess && "text-muted-foreground"+ )}+ >+ {label}+ </label>+ </div>+ ))}+ </VStack>+ </VStack>+ </CollapsibleContent>+ </Collapsible>+ );+}+export default MakeMethodTools;diff --git a/apps/erp/app/modules/production/ui/Jobs/JobBillOfProcess.tsx b/apps/erp/app/modules/production/ui/Jobs/JobBillOfProcess.tsxindex 3fd5392605..ae2610a87f 100644--- a/apps/erp/app/modules/production/ui/Jobs/JobBillOfProcess.tsx+++ b/apps/erp/app/modules/production/ui/Jobs/JobBillOfProcess.tsx@@ -2919,7 +2919,7 @@ function ToolsListItem({const date = updatedAt ?? createdAt;return (- <div className={cn("border-b p-6", className)}>+ <div className={cn("border-b p-6 bg-card", className)}>{disclosure.isOpen ? (<ValidatedFormaction={path.to.jobOperationTool(id)}diff --git a/apps/erp/app/modules/sales/ui/Quotes/QuoteBillOfProcess.tsx b/apps/erp/app/modules/sales/ui/Quotes/QuoteBillOfProcess.tsxindex d411a29f3b..2568f4c70c 100644--- a/apps/erp/app/modules/sales/ui/Quotes/QuoteBillOfProcess.tsx+++ b/apps/erp/app/modules/sales/ui/Quotes/QuoteBillOfProcess.tsx@@ -2448,7 +2448,7 @@ function ToolsListItem({const date = updatedAt ?? createdAt;return (- <div className={cn("border-b p-6", className)}>+ <div className={cn("border-b p-6 bg-card", className)}>{disclosure.isOpen ? (<ValidatedFormaction={path.to.quoteOperationTool(id)}@@ -2581,7 +2581,7 @@ function ToolsForm({return (<div className="flex flex-col gap-6">- <div className="p-6 border rounded-lg">+ <div className="p-6 border rounded-lg bg-card"><ValidatedFormaction={path.to.newQuoteOperationTool}method="post"diff --git a/packages/database/supabase/functions/get-method/index.ts b/packages/database/supabase/functions/get-method/index.tsindex 07af96c970..6170047ae2 100644--- a/packages/database/supabase/functions/get-method/index.ts+++ b/packages/database/supabase/functions/get-method/index.ts@@ -39,6 +39,15 @@ import { KyselyDatabase } from "../lib/postgres/index.ts";const pool = getConnectionPool(1);const db = getDatabaseClient<DB>(pool);+const partsValidator = z.object({+ billOfMaterial: z.boolean().default(true),+ billOfProcess: z.boolean().default(true),+ parameters: z.boolean().default(true),+ tools: z.boolean().default(true),+ steps: z.boolean().default(true),+ workInstructions: z.boolean().default(true),+}).default({});+const payloadValidator = z.object({type: z.enum(["itemToItem",@@ -61,6 +70,7 @@ const payloadValidator = z.object({companyId: z.string(),userId: z.string(),configuration: z.record(z.unknown()).optional(),+ parts: partsValidator,});serve(async (req: Request) => {@@ -70,7 +80,7 @@ serve(async (req: Request) => {const payload = await req.json();try {- const { type, sourceId, targetId, companyId, userId, configuration } =+ const { type, sourceId, targetId, companyId, userId, configuration, parts } =payloadValidator.parse(payload);console.log({@@ -80,6 +90,7 @@ serve(async (req: Request) => {targetId,companyId,userId,+ parts,configuration,});@@ -132,18 +143,22 @@ serve(async (req: Request) => {}const [sourceMaterials, sourceOperations] = await Promise.all([- client- .from("methodMaterial")- .select("*")- .eq("makeMethodId", sourceMakeMethod.data.id)- .eq("companyId", companyId),- client- .from("methodOperation")- .select(- "*, methodOperationTool(*), methodOperationParameter(*), methodOperationStep(*)"- )- .eq("makeMethodId", sourceMakeMethod.data.id)- .eq("companyId", companyId),+ parts.billOfMaterial+ ? client+ .from("methodMaterial")+ .select("*")+ .eq("makeMethodId", sourceMakeMethod.data.id)+ .eq("companyId", companyId)+ : Promise.resolve({ data: [], error: null }),+ parts.billOfProcess+ ? client+ .from("methodOperation")+ .select(+ "*, methodOperationTool(*), methodOperationParameter(*), methodOperationStep(*)"+ )+ .eq("makeMethodId", sourceMakeMethod.data.id)+ .eq("companyId", companyId)+ : Promise.resolve({ data: [], error: null }),]);if (sourceMaterials.error || sourceOperations.error) {@@ -153,18 +168,22 @@ serve(async (req: Request) => {await db.transaction().execute(async (trx) => {// Delete existing materials and operations from target methodawait Promise.all([- trx- .deleteFrom("methodMaterial")- .where("makeMethodId", "=", targetMakeMethod.data.id)- .execute(),- trx- .deleteFrom("methodOperation")- .where("makeMethodId", "=", targetMakeMethod.data.id)- .execute(),+ parts.billOfMaterial+ ? trx+ .deleteFrom("methodMaterial")+ .where("makeMethodId", "=", targetMakeMethod.data.id)+ .execute()+ : Promise.resolve(),+ parts.billOfProcess+ ? trx+ .deleteFrom("methodOperation")+ .where("makeMethodId", "=", targetMakeMethod.data.id)+ .execute()+ : Promise.resolve(),]);// Copy materials from source to target- if (sourceMaterials.data && sourceMaterials.data.length > 0) {+ if (parts.billOfMaterial && sourceMaterials.data && sourceMaterials.data.length > 0) {await trx.insertInto("methodMaterial").values(@@ -180,7 +199,7 @@ serve(async (req: Request) => {}// Copy operations from source to target- if (sourceOperations.data && sourceOperations.data.length > 0) {+ if (parts.billOfProcess && sourceOperations.data && sourceOperations.data.length > 0) {const operationIds = await trx.insertInto("methodOperation").values(@@ -190,12 +209,18 @@ serve(async (req: Request) => {methodOperationParameter: _parameters,methodOperationStep: _attributes,...operation- }) => ({- ...operation,- id: undefined, // Let the database generate a new ID- makeMethodId: targetMakeMethod.data.id!,- createdBy: userId,- })+ }) => {+ const insert = {+ ...operation,+ id: undefined, // Let the database generate a new ID+ makeMethodId: targetMakeMethod.data.id!,+ createdBy: userId,+ };+ if (!parts.workInstructions) {+ insert.workInstruction = {};+ }+ return insert;+ })).returning(["id"])@@ -214,6 +239,7 @@ serve(async (req: Request) => {const operationId = operationIds[index].id;if (+ parts.tools &&operationId &&Array.isArray(methodOperationTool) &&methodOperationTool.length > 0@@ -234,6 +260,7 @@ serve(async (req: Request) => {if (!procedureId) {if (+ parts.parameters &&Array.isArray(methodOperationParameter) &&methodOperationParameter.length > 0) {@@ -252,6 +279,7 @@ serve(async (req: Request) => {}if (+ parts.steps &&Array.isArray(methodOperationStep) &&methodOperationStep.length > 0) {diff --git a/packages/utils/src/themes.ts b/packages/utils/src/themes.tsindex 29128762cd..38cd880c1e 100644--- a/packages/utils/src/themes.ts+++ b/packages/utils/src/themes.ts@@ -98,7 +98,7 @@ export const themes = [dark: {background: "20 33% 4%",foreground: "0 0% 98%",- card: "0 0% 8.9%",+ card: "0 0% 5%","card-foreground": "0 0% 98%",popover: "0 0% 8.9%","popover-foreground": "0 0% 98%",@@ -158,7 +158,7 @@ export const themes = [dark: {background: "0 0% 6.9%",foreground: "0 0% 98%",- card: "0 0% 8.9%",+ card: "0 0% 5%","card-foreground": "0 0% 98%",popover: "0 0% 8.9%","popover-foreground": "0 0% 98%",@@ -218,7 +218,7 @@ export const themes = [dark: {background: "20 14.3% 6.1%",foreground: "60 9.1% 97.8%",- card: "20 14.3% 8.9%",+ card: "20 14.3% 5%","card-foreground": "60 9.1% 97.8%",popover: "20 14.3% 8.9%","popover-foreground": "60 9.1% 97.8%",@@ -271,14 +271,14 @@ export const themes = ["destructive-foreground": "60 9.1% 97.8%",border: "20 5.9% 90%",input: "20 5.9% 90%",- ring: "20 14.3% 4.1%",+ ring: "47.9 14.3% 4.1%",success: "142 70% 45%","success-foreground": "0 0% 98%"},dark: {background: "20 14.3% 6.1%",foreground: "61 9.1% 97.8%",- card: "20 14.3% 8.9%",+ card: "20 14.3% 5%","card-foreground": "61 9.1% 97.8%",popover: "20 14.3% 4.1%","popover-foreground": "61 9.1% 97.8%",@@ -342,7 +342,7 @@ export const themes = [foreground: "0 0% 95%",popover: "151 0% 9%","popover-foreground": "151 0% 95%",- card: "151 0% 9%",+ card: "151 0% 5%","card-foreground": "151 0% 95%",primary: "171 98% 59%","primary-foreground": "144.9 80.4% 10%",@@ -358,7 +358,7 @@ export const themes = ["destructive-foreground": "0 85.7% 97.3%",border: "151 3.7% 15.9%",input: "151 3.7% 15.9%",- ring: "142.4 71.8% 29.2%",+ ring: "171 71.8% 29.2%",success: "142 70% 45%","success-foreground": "0 0% 98%"}@@ -402,7 +402,7 @@ export const themes = [foreground: "220 0% 95%",popover: "216 0% 9%","popover-foreground": "220 0% 95%",- card: "220 10% 8.9%",+ card: "220 10% 5%","card-foreground": "220 10% 95%",primary: "216 98% 52%","primary-foreground": "216 80.4% 100%",@@ -453,14 +453,14 @@ export const themes = ["destructive-foreground": "210 20% 98%",border: "220 13% 91%",input: "220 13% 91%",- ring: "262.1 83.3% 57.8%",+ ring: "238 83.3% 57.8%",success: "142 70% 45%","success-foreground": "0 0% 98%"},dark: {background: "263 41.4 6.1%",foreground: "263 20% 98%",- card: "263 41.4 8.9%",+ card: "263 41.4 5%","card-foreground": "210 20% 98%",popover: "263 41.4 8.9%","popover-foreground": "210 20% 98%",