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: auto-generated material id edits
Brad Barbinfec1f03e05b5
diff --git a/apps/erp/app/components/Chat/ChatInput.tsx b/apps/erp/app/components/Chat/ChatInput.tsxindex 4a49a1a250..471739b8f8 100644--- a/apps/erp/app/components/Chat/ChatInput.tsx+++ b/apps/erp/app/components/Chat/ChatInput.tsx@@ -1,4 +1,3 @@-import { useArtifacts } from "@ai-sdk-tools/artifacts/client";import {useChatActions,useChatId,@@ -49,10 +48,10 @@ export const ChatInput = forwardRef<RecordButtonRef, ChatInputProps>("suggestions");- const { current } = useArtifacts({- exclude: ["chat-title", "followup-questions"],- });- const isCanvasVisible = !!current;+ // const { } = useArtifacts({+ // exclude: ["chat-title", "followup-questions"],+ // });+ // const isCanvasVisible = false;const {input,@@ -99,8 +98,8 @@ export const ChatInput = forwardRef<RecordButtonRef, ChatInputProps>(<divclassName={cn("transition-all duration-300 ease-in-out",- hasMessages ? "absolute bottom-6 left-0 z-20" : "",- isCanvasVisible ? "right-[603px]" : "right-0"+ hasMessages ? "absolute bottom-6 left-0 z-20" : ""+ // isCanvasVisible ? "right-[603px]" : "right-0")}><div className="mx-auto w-full pt-2 relative">diff --git a/apps/erp/app/modules/items/ui/Materials/MaterialsTable.tsx b/apps/erp/app/modules/items/ui/Materials/MaterialsTable.tsxindex 0e2171ede3..cd77592110 100644--- a/apps/erp/app/modules/items/ui/Materials/MaterialsTable.tsx+++ b/apps/erp/app/modules/items/ui/Materials/MaterialsTable.tsx@@ -77,6 +77,8 @@ const MaterialsTable = memo(({ data, tags, count }: MaterialsTableProps) => {const navigate = useNavigate();const permissions = usePermissions();+ console.log(data);+const deleteItemModal = useDisclosure();const [selectedItem, setSelectedItem] = useState<Material | null>(null);@@ -129,7 +131,9 @@ const MaterialsTable = memo(({ data, tags, count }: MaterialsTableProps) => {{accessorKey: "materialSubstanceId",header: "Substance",- cell: (item) => <Enumerable value={item.getValue<string>()} />,+ cell: ({ row }) => (+ <Enumerable value={row.original.materialSubstance} />+ ),meta: {filter: {type: "fetcher",@@ -146,7 +150,7 @@ const MaterialsTable = memo(({ data, tags, count }: MaterialsTableProps) => {{accessorKey: "materialFormId",header: "Shape",- cell: (item) => <Enumerable value={item.getValue<string>()} />,+ cell: ({ row }) => <Enumerable value={row.original.materialForm} />,meta: {filter: {type: "fetcher",diff --git a/apps/erp/app/modules/quality/ui/IssueWorkflows/IssueWorkflowForm.tsx b/apps/erp/app/modules/quality/ui/IssueWorkflows/IssueWorkflowForm.tsxindex 18bbf79f6f..1c3354d057 100644--- a/apps/erp/app/modules/quality/ui/IssueWorkflows/IssueWorkflowForm.tsx+++ b/apps/erp/app/modules/quality/ui/IssueWorkflows/IssueWorkflowForm.tsx@@ -174,9 +174,8 @@ const IssueWorkflowForm = ({<span className="hidden md:inline">Issue</span> Workflow</Heading><p className="text-sm text-muted-foreground">- Issue workflows are used as a starting point for issues. Each- issue workflow uses a workflow to create the issue. A single- workflow can be used in multiple workflows.+ Issue workflows defined the preset values for an issue. For+ example, you can have an 8D workflow or a containment workflow.</p></VStack></HStack>diff --git a/apps/erp/app/routes/api+/items.forms.ts b/apps/erp/app/routes/api+/items.forms.tsindex 534b83dea0..935b4c6192 100644--- a/apps/erp/app/routes/api+/items.forms.ts+++ b/apps/erp/app/routes/api+/items.forms.ts@@ -1,10 +1,9 @@import { requirePermissions } from "@carbon/auth/auth.server";import type { LoaderFunctionArgs } from "@vercel/remix";-import { json } from "@vercel/remix";import { getMaterialFormsList } from "~/modules/items";export async function loader({ request }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {});- return json(await getMaterialFormsList(client, companyId));+ return await getMaterialFormsList(client, companyId);}diff --git a/apps/erp/app/routes/x+/items+/update.tsx b/apps/erp/app/routes/x+/items+/update.tsxindex 9550622b8b..4bf99768cd 100644--- a/apps/erp/app/routes/x+/items+/update.tsx+++ b/apps/erp/app/routes/x+/items+/update.tsx@@ -18,6 +18,8 @@ export async function action({ request }: ActionFunctionArgs) {return json({ error: { message: "Invalid form data" }, data: null });}+ console.log({ field, value });+switch (field) {case "defaultMethodType":case "itemTrackingType":@@ -83,16 +85,17 @@ export async function action({ request }: ActionFunctionArgs) {const materialSubstance = await client.from("materialSubstance").select("name, code")- .eq("code", value)+ .eq("id", value).single();name = materialSubstance.data?.name ?? "";code = materialSubstance.data?.code ?? "";+ console.log({ materialSubstance });}if (field === "materialFormId") {const materialForm = await client.from("materialForm").select("name, code")- .eq("code", value)+ .eq("id", value).single();name = materialForm.data?.name ?? "";code = materialForm.data?.code ?? "";@@ -101,7 +104,7 @@ export async function action({ request }: ActionFunctionArgs) {const materialType = await client.from("materialType").select("name, code")- .eq("code", value)+ .eq("id", value).single();name = materialType.data?.name ?? "";code = materialType.data?.code ?? "";@@ -133,6 +136,8 @@ export async function action({ request }: ActionFunctionArgs) {}for await (const id of items as string[]) {+ console.log(`Processing item ID: ${id}`);+const item = await client.from("item").select("readableId")@@ -140,9 +145,12 @@ export async function action({ request }: ActionFunctionArgs) {.eq("companyId", companyId).single();+ console.log(`Item query result:`, item);const readableId = item.data?.readableId;if (readableId) {+ console.log(`Found readableId: ${readableId}`);+const [materialDetails, relatedItems] = await Promise.all([client.rpc("get_material_naming_details", { readable_id: readableId })@@ -154,8 +162,13 @@ export async function action({ request }: ActionFunctionArgs) {.eq("companyId", companyId),]);+ console.log(`Material details result:`, materialDetails);+ console.log(`Related items result:`, relatedItems);+if (materialDetails.data) {const namingDetails = materialDetails.data;+ console.log(`Original naming details:`, namingDetails);+if (field === "materialSubstanceId") {namingDetails.substance = name;namingDetails.substanceCode = code;@@ -178,19 +191,30 @@ export async function action({ request }: ActionFunctionArgs) {namingDetails.dimensions = name;}+ console.log(`Updated naming details:`, namingDetails);+const newMaterialId = getMaterialId(namingDetails);const newDescription = getMaterialDescription(namingDetails);+ console.log(`New material ID: ${newMaterialId}`);+ console.log(`New description: ${newDescription}`);+const relatedItemIds = relatedItems.data?.map((item) => item.id);+ console.log(`Related item IDs:`, relatedItemIds);if (relatedItemIds) {+ console.log(`Updating ${relatedItemIds.length} related items`);+const itemUpdateResult = await client.from("item").update({ readableId: newMaterialId, name: newDescription }).in("id", relatedItemIds as string[]).eq("companyId", companyId);+ console.log(`Item update result:`, itemUpdateResult);+if (itemUpdateResult.error) {+ console.error(`Item update error:`, itemUpdateResult.error);return json(itemUpdateResult);}}@@ -216,19 +240,31 @@ export async function action({ request }: ActionFunctionArgs) {updateData.materialTypeId = null;}+ console.log(`Material update data:`, updateData);+ console.log(`Updating material with readableId: ${readableId}`);+const update = await client.from("material").update(updateData).eq("id", readableId).eq("companyId", companyId);+ console.log(`Material update result:`, update);+if (update.error) {+ console.error(`Material update error:`, update.error);return json({error: { message: update.error.message },data: null,});}+ } else {+ console.log(+ `No material details found for readableId: ${readableId}`+ );}+ } else {+ console.log(`No readableId found for item ID: ${id}`);}}diff --git a/apps/erp/app/routes/x+/resources+/processes.delete.$processId.tsx b/apps/erp/app/routes/x+/resources+/processes.delete.$processId.tsxindex 0cb6e18d88..de4ec4efb1 100644--- a/apps/erp/app/routes/x+/resources+/processes.delete.$processId.tsx+++ b/apps/erp/app/routes/x+/resources+/processes.delete.$processId.tsx@@ -51,7 +51,7 @@ export async function action({ request, params }: ActionFunctionArgs) {path.to.processes,await flash(request,- error(deleteProcessError, "Failed to delete process")+ error(deleteProcessError, deleteProcessError.details)));}diff --git a/apps/erp/app/routes/x+/resources+/work-centers.delete.$id.tsx b/apps/erp/app/routes/x+/resources+/work-centers.delete.$id.tsxindex 0ca215471f..5221bab173 100644--- a/apps/erp/app/routes/x+/resources+/work-centers.delete.$id.tsx+++ b/apps/erp/app/routes/x+/resources+/work-centers.delete.$id.tsx@@ -27,7 +27,7 @@ export async function action({ request, params }: LoaderFunctionArgs) {path.to.workCenters,await flash(request,- error(deactivateWorkCenter.error, "Failed to deactivate work center")+ error(deactivateWorkCenter.error, deactivateWorkCenter.error.details)));}diff --git a/packages/database/supabase/migrations/20251122152701_materials-view-fix.sql b/packages/database/supabase/migrations/20251122152701_materials-view-fix.sqlnew file mode 100644index 0000000000..14072d49fa--- /dev/null+++ b/packages/database/supabase/migrations/20251122152701_materials-view-fix.sql@@ -0,0 +1,87 @@+CREATE OR REPLACE VIEW "materials" WITH (SECURITY_INVOKER=true) AS+WITH latest_items AS (+ SELECT DISTINCT ON (i."readableId", i."companyId")+ i.*,++ mu."modelPath",+ mu."thumbnailPath" as "modelThumbnailPath",+ mu."name" as "modelName",+ mu."size" as "modelSize"+ FROM "item" i+ LEFT JOIN "modelUpload" mu ON mu.id = i."modelUploadId"+ ORDER BY i."readableId", i."companyId", i."createdAt" DESC NULLS LAST+),+item_revisions AS (+ SELECT+ i."readableId",+ i."companyId",+ json_agg(+ json_build_object(+ 'id', i.id,+ 'revision', i."revision",+ 'methodType', i."defaultMethodType",+ 'type', i."type"+ ) ORDER BY i."createdAt"+ ) as "revisions"+ FROM "item" i+ GROUP BY i."readableId", i."companyId"+)+SELECT+ i."active",+ i."assignee",+ i."defaultMethodType",+ i."description",+ i."itemTrackingType",+ i."name",+ i."replenishmentSystem",+ i."unitOfMeasureCode",+ i."notes",+ i."revision",+ i."readableId",+ i."readableIdWithRevision",+ i."id",+ i."companyId",+ CASE+ WHEN i."thumbnailPath" IS NULL AND i."modelThumbnailPath" IS NOT NULL THEN i."modelThumbnailPath"+ ELSE i."thumbnailPath"+ END as "thumbnailPath",+ i."modelUploadId",+ i."modelPath",+ i."modelName",+ i."modelSize",+ ps."supplierIds",+ uom.name as "unitOfMeasure",+ ir."revisions",+ mf."name" AS "materialForm",+ ms."name" AS "materialSubstance",+ md."name" AS "dimensions",+ mfin."name" AS "finish",+ mg."name" AS "grade",+ mt."name" AS "materialType",+ m."materialSubstanceId",+ m."materialFormId",+ m."customFields",+ m."tags",+ i."createdBy",+ i."createdAt",+ i."updatedBy",+ i."updatedAt"+FROM "material" m+ INNER JOIN latest_items i ON i."readableId" = m."id" AND i."companyId" = m."companyId"+ LEFT JOIN item_revisions ir ON ir."readableId" = m."id" AND ir."companyId" = i."companyId"+ LEFT JOIN (+ SELECT+ ps."itemId",+ ps."companyId",+ string_agg(ps."supplierPartId", ',') AS "supplierIds"+ FROM "supplierPart" ps+ GROUP BY ps."itemId", ps."companyId"+ ) ps ON ps."itemId" = i."id" AND ps."companyId" = i."companyId"+ LEFT JOIN "modelUpload" mu ON mu.id = i."modelUploadId"+ LEFT JOIN "unitOfMeasure" uom ON uom.code = i."unitOfMeasureCode" AND uom."companyId" = i."companyId"+ LEFT JOIN "materialForm" mf ON mf."id" = m."materialFormId"+ LEFT JOIN "materialSubstance" ms ON ms."id" = m."materialSubstanceId"+ LEFT JOIN "materialDimension" md ON m."dimensionId" = md."id"+ LEFT JOIN "materialFinish" mfin ON m."finishId" = mfin."id"+ LEFT JOIN "materialGrade" mg ON m."gradeId" = mg."id"+ LEFT JOIN "materialType" mt ON m."materialTypeId" = mt."id";\ No newline at end of file