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: add operation to material
Brad Barbin8616c95c32eb
diff --git a/apps/carbon/app/modules/items/items.models.ts b/apps/carbon/app/modules/items/items.models.tsindex 3996c55660..09a3666a4f 100644--- a/apps/carbon/app/modules/items/items.models.ts+++ b/apps/carbon/app/modules/items/items.models.ts@@ -141,6 +141,7 @@ export const methodMaterialValidator = z}),itemId: z.string().optional(),itemReadableId: z.string().optional(),+ methodOperationId: zfd.text(z.string().optional()),// description: z.string().min(1, { message: "Description is required" }),quantity: zfd.numeric(z.number().min(0)),unitOfMeasureCode: zdiff --git a/apps/carbon/app/modules/items/ui/Item/BillOfMaterial.tsx b/apps/carbon/app/modules/items/ui/Item/BillOfMaterial.tsxindex 3dc3cef807..f5df65c873 100644--- a/apps/carbon/app/modules/items/ui/Item/BillOfMaterial.tsx+++ b/apps/carbon/app/modules/items/ui/Item/BillOfMaterial.tsx@@ -39,6 +39,7 @@ import { SortableList, SortableListItem } from "~/components/SortableList";import { useUser } from "~/hooks";import { useSupabase } from "~/lib/supabase";import { path } from "~/utils/path";+import type { methodOperationValidator } from "../../items.models";import { methodItemType, methodMaterialValidator } from "../../items.models";import type { MethodItemType, MethodType } from "../../types";import { MethodIcon, MethodItemTypeIcon } from "./MethodIcon";@@ -47,6 +48,8 @@ type Material = z.infer<typeof methodMaterialValidator> & {description: string;};+type Operation = z.infer<typeof methodOperationValidator>;+type ItemWithData = SortableItem & {data: Material;};@@ -54,6 +57,7 @@ type ItemWithData = SortableItem & {type BillOfMaterialProps = {makeMethodId: string;materials: Material[];+ operations: Operation[];};function makeItems(materials: Material[]): ItemWithData[] {@@ -102,7 +106,11 @@ const initialMethodMaterial: Omit<Material, "makeMethodId" | "order"> & {unitOfMeasureCode: "EA",};-const BillOfMaterial = ({ makeMethodId, materials }: BillOfMaterialProps) => {+const BillOfMaterial = ({+ makeMethodId,+ materials,+ operations,+}: BillOfMaterialProps) => {const fetcher = useFetcher();const [items, setItems] = useState<ItemWithData[]>(@@ -313,6 +321,7 @@ const BillOfMaterial = ({ makeMethodId, materials }: BillOfMaterialProps) => {item={item}setItems={setItems}setSelectedItemId={setSelectedItemId}+ methodOperations={operations}/></motion.div></motion.div>@@ -367,10 +376,12 @@ function MaterialForm({item,setItems,setSelectedItemId,+ methodOperations,}: {item: ItemWithData;setItems: Dispatch<SetStateAction<ItemWithData[]>>;setSelectedItemId: Dispatch<SetStateAction<string | null>>;+ methodOperations: Operation[];}) {const { supabase } = useSupabase();const methodMaterialFetcher = useFetcher<{ id: string }>();@@ -509,15 +520,26 @@ function MaterialForm({onItemChange(value?.value as string);}}/>- <InputControlled- name="description"- label="Description"- isReadOnly- value={itemData.description}- onChange={(newValue) => {- setItemData((d) => ({ ...d, description: newValue }));- }}+ <Select+ name="methodOperationId"+ label="Operation"+ isClearable+ options={methodOperations.map((o) => ({+ value: o.id!,+ label: o.description,+ }))}/>+ </div>+ <InputControlled+ name="description"+ label="Description"+ isReadOnly+ value={itemData.description}+ onChange={(newValue) => {+ setItemData((d) => ({ ...d, description: newValue }));+ }}+ />+ <div className="grid w-full gap-x-8 gap-y-4 grid-cols-1 lg:grid-cols-3"><DefaultMethodTypename="methodType"label="Method Type"diff --git a/apps/carbon/app/routes/x+/fixture+/$itemId.manufacturing.$makeMethodId.$materialId.tsx b/apps/carbon/app/routes/x+/fixture+/$itemId.manufacturing.$makeMethodId.$materialId.tsxindex faa7b4c354..3ef1d13e77 100644--- a/apps/carbon/app/routes/x+/fixture+/$itemId.manufacturing.$makeMethodId.$materialId.tsx+++ b/apps/carbon/app/routes/x+/fixture+/$itemId.manufacturing.$makeMethodId.$materialId.tsx@@ -81,6 +81,7 @@ export async function loader({ request, params }: LoaderFunctionArgs) {description: m.item?.name ?? "",methodType: m.methodType as MethodType,itemType: m.itemType as MethodItemType,+ methodOperationId: m.methodOperationId ?? undefined,})) ?? [],methodOperations:methodOperations.data?.map((operation) => ({@@ -118,6 +119,7 @@ export default function MethodMaterialMakePage() {key={`bom:${itemId}:${makeMethodId}:${materialId}`}makeMethodId={makeMethodId}materials={methodMaterials}+ operations={methodOperations}/></VStack>);diff --git a/apps/carbon/app/routes/x+/fixture+/$itemId.manufacturing.method.tsx b/apps/carbon/app/routes/x+/fixture+/$itemId.manufacturing.method.tsxindex bd56dd4e47..89c17bf742 100644--- a/apps/carbon/app/routes/x+/fixture+/$itemId.manufacturing.method.tsx+++ b/apps/carbon/app/routes/x+/fixture+/$itemId.manufacturing.method.tsx@@ -32,6 +32,8 @@ export default function MakeMethodRoute() {makeMethodId={makeMethodId}// @ts-ignorematerials={manufacturingRouteData?.methodMaterials ?? []}+ // @ts-ignore+ operations={manufacturingRouteData?.methodOperations}/></VStack>);diff --git a/apps/carbon/app/routes/x+/part+/$itemId.manufacturing.$makeMethodId.$materialId.tsx b/apps/carbon/app/routes/x+/part+/$itemId.manufacturing.$makeMethodId.$materialId.tsxindex 287192a462..fc64a46cce 100644--- a/apps/carbon/app/routes/x+/part+/$itemId.manufacturing.$makeMethodId.$materialId.tsx+++ b/apps/carbon/app/routes/x+/part+/$itemId.manufacturing.$makeMethodId.$materialId.tsx@@ -79,6 +79,7 @@ export async function loader({ request, params }: LoaderFunctionArgs) {methodMaterials.data?.map((m) => ({...m,description: m.item?.name ?? "",+ methodOperationId: m.methodOperationId ?? undefined,methodType: m.methodType as MethodType,itemType: m.itemType as MethodItemType,})) ?? [],@@ -118,6 +119,7 @@ export default function MethodMaterialMakePage() {key={`bom:${itemId}:${makeMethodId}:${materialId}`}makeMethodId={makeMethodId}materials={methodMaterials}+ operations={methodOperations}/></VStack>);diff --git a/apps/carbon/app/routes/x+/part+/$itemId.manufacturing.method.tsx b/apps/carbon/app/routes/x+/part+/$itemId.manufacturing.method.tsxindex e0c833a472..18f7c9fc9c 100644--- a/apps/carbon/app/routes/x+/part+/$itemId.manufacturing.method.tsx+++ b/apps/carbon/app/routes/x+/part+/$itemId.manufacturing.method.tsx@@ -128,6 +128,8 @@ export default function MakeMethodRoute() {makeMethodId={makeMethodId}// @ts-ignorematerials={manufacturingRouteData?.methodMaterials ?? []}+ // @ts-ignore+ operations={manufacturingRouteData?.methodOperations}/></VStack>);diff --git a/packages/database/src/types.ts b/packages/database/src/types.tsindex eacd57ece1..5e56fbc23b 100644--- a/packages/database/src/types.ts+++ b/packages/database/src/types.ts@@ -8189,6 +8189,7 @@ export type Database = {itemType: stringmakeMethodId: stringmaterialMakeMethodId: string | null+ methodOperationId: string | nullmethodType: Database["public"]["Enums"]["methodType"]order: numberquantity: number@@ -8207,6 +8208,7 @@ export type Database = {itemType?: stringmakeMethodId: stringmaterialMakeMethodId?: string | null+ methodOperationId?: string | nullmethodType?: Database["public"]["Enums"]["methodType"]order?: numberquantity: number@@ -8225,6 +8227,7 @@ export type Database = {itemType?: stringmakeMethodId?: stringmaterialMakeMethodId?: string | null+ methodOperationId?: string | nullmethodType?: Database["public"]["Enums"]["methodType"]order?: numberquantity?: number@@ -8324,6 +8327,13 @@ export type Database = {referencedRelation: "makeMethod"referencedColumns: ["id"]},+ {+ foreignKeyName: "methodMaterial_methodOperation_fkey"+ columns: ["methodOperationId"]+ isOneToOne: false+ referencedRelation: "methodOperation"+ referencedColumns: ["id"]+ },{foreignKeyName: "methodMaterial_unitOfMeasureCode_fkey"columns: ["unitOfMeasureCode", "companyId"]diff --git a/packages/database/supabase/functions/lib/types.ts b/packages/database/supabase/functions/lib/types.tsindex eacd57ece1..5e56fbc23b 100644--- a/packages/database/supabase/functions/lib/types.ts+++ b/packages/database/supabase/functions/lib/types.ts@@ -8189,6 +8189,7 @@ export type Database = {itemType: stringmakeMethodId: stringmaterialMakeMethodId: string | null+ methodOperationId: string | nullmethodType: Database["public"]["Enums"]["methodType"]order: numberquantity: number@@ -8207,6 +8208,7 @@ export type Database = {itemType?: stringmakeMethodId: stringmaterialMakeMethodId?: string | null+ methodOperationId?: string | nullmethodType?: Database["public"]["Enums"]["methodType"]order?: numberquantity: number@@ -8225,6 +8227,7 @@ export type Database = {itemType?: stringmakeMethodId?: stringmaterialMakeMethodId?: string | null+ methodOperationId?: string | nullmethodType?: Database["public"]["Enums"]["methodType"]order?: numberquantity?: number@@ -8324,6 +8327,13 @@ export type Database = {referencedRelation: "makeMethod"referencedColumns: ["id"]},+ {+ foreignKeyName: "methodMaterial_methodOperation_fkey"+ columns: ["methodOperationId"]+ isOneToOne: false+ referencedRelation: "methodOperation"+ referencedColumns: ["id"]+ },{foreignKeyName: "methodMaterial_unitOfMeasureCode_fkey"columns: ["unitOfMeasureCode", "companyId"]diff --git a/packages/database/supabase/migrations/20240714033845_material-operation.sql b/packages/database/supabase/migrations/20240714033845_material-operation.sqlnew file mode 100644index 0000000000..0779fe6f0b--- /dev/null+++ b/packages/database/supabase/migrations/20240714033845_material-operation.sql@@ -0,0 +1,2 @@+ALTER TABLE "methodMaterial" ADD COLUMN "methodOperationId" TEXT;+ALTER TABLE "methodMaterial" ADD CONSTRAINT "methodMaterial_methodOperation_fkey" FOREIGN KEY ("methodOperationId") REFERENCES "methodOperation" ("id") ON UPDATE CASCADE ON DELETE SET NULL;\ No newline at end of file