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: BoP routes
Brad Barbin616b3b87dc9b
diff --git a/apps/carbon/app/modules/sales/sales.service.ts b/apps/carbon/app/modules/sales/sales.service.tsindex 0eb350eae3..f459971b76 100644--- a/apps/carbon/app/modules/sales/sales.service.ts+++ b/apps/carbon/app/modules/sales/sales.service.ts@@ -679,6 +679,17 @@ export async function getQuoteOperationsByLine(.eq("quoteLineId", quoteLineId);}+export async function getQuoteOperationsByMethodId(+ client: SupabaseClient<Database>,+ quoteMakeMethodId: string+) {+ return client+ .from("quoteOperation")+ .select("*")+ .eq("quoteMakeMethodId", quoteMakeMethodId)+ .order("order", { ascending: true });+}+export async function getQuoteOperations(client: SupabaseClient<Database>,quoteId: stringdiff --git a/apps/carbon/app/modules/sales/ui/Quotes/QuoteBoMExplorer.tsx b/apps/carbon/app/modules/sales/ui/Quotes/QuoteBoMExplorer.tsxindex d854c09779..fc8f1aa2aa 100644--- a/apps/carbon/app/modules/sales/ui/Quotes/QuoteBoMExplorer.tsx+++ b/apps/carbon/app/modules/sales/ui/Quotes/QuoteBoMExplorer.tsx@@ -158,7 +158,11 @@ function NodeData({ node }: { node: FlatTreeItem<QuoteMethod> }) {function getNodePath(node: FlatTreeItem<QuoteMethod>) {return node.data.isRoot- ? path.to.quoteLineMethod(node.data.quoteId, node.data.quoteLineId)+ ? path.to.quoteLineMethod(+ node.data.quoteId,+ node.data.quoteLineId,+ node.data.quoteMaterialMakeMethodId+ ): path.to.quoteLineMaterial(node.data.quoteId,node.data.quoteLineId,diff --git a/apps/carbon/app/routes/x+/quote+/$quoteId.$lineId.method.$methodId.tsx b/apps/carbon/app/routes/x+/quote+/$quoteId.$lineId.method.$methodId.tsxnew file mode 100644index 0000000000..4973144304--- /dev/null+++ b/apps/carbon/app/routes/x+/quote+/$quoteId.$lineId.method.$methodId.tsx@@ -0,0 +1,72 @@+import { VStack } from "@carbon/react";+import { json, redirect, useLoaderData, useParams } from "@remix-run/react";++import {+ getQuoteOperationsByMethodId,+ QuoteBillOfMaterial,+ QuoteBillOfProcess,+} from "~/modules/sales";+import { path } from "~/utils/path";++import type { LoaderFunctionArgs } from "@remix-run/node";+import { requirePermissions } from "~/services/auth/auth.server";+import { flash } from "~/services/session.server";+import { error } from "~/utils/result";++export async function loader({ request, params }: LoaderFunctionArgs) {+ const { client } = await requirePermissions(request, {+ view: "sales",+ });++ const { quoteId, lineId, methodId } = params;+ if (!quoteId) throw new Error("Could not find quoteId");+ if (!lineId) throw new Error("Could not find lineId");+ if (!methodId) throw new Error("Could not find methodId");++ const [operations] = await Promise.all([+ getQuoteOperationsByMethodId(client, methodId),+ ]);++ if (operations.error) {+ throw redirect(+ path.to.quoteLine(quoteId, lineId),+ await flash(+ request,+ error(operations.error, "Failed to load quote method")+ )+ );+ }++ return json({+ operations:+ operations.data?.map((o) => ({+ ...o,+ description: o.description ?? "",+ equipmentTypeId: o.equipmentTypeId ?? undefined,+ quoteMakeMethodId: o.quoteMakeMethodId ?? methodId,+ })) ?? [],+ });+}++export default function QuoteMakeMethodRoute() {+ const { methodId } = useParams();+ if (!methodId) throw new Error("Could not find methodId");++ const { operations } = useLoaderData<typeof loader>();++ return (+ <VStack spacing={2} className="p-2">+ <QuoteBillOfProcess+ key={`bop:${methodId}`}+ quoteMakeMethodId={methodId}+ operations={operations}+ />+ <QuoteBillOfMaterial+ key={`bom:${methodId}`}+ quoteMakeMethodId={methodId}+ materials={[]}+ operations={operations}+ />+ </VStack>+ );+}diff --git a/apps/carbon/app/routes/x+/quote+/$quoteId.$lineId.method.tsx b/apps/carbon/app/routes/x+/quote+/$quoteId.$lineId.method.tsxdeleted file mode 100644index b1bbe04447..0000000000--- a/apps/carbon/app/routes/x+/quote+/$quoteId.$lineId.method.tsx+++ /dev/null@@ -1,41 +0,0 @@-import { VStack } from "@carbon/react";-import { useParams } from "@remix-run/react";-import type { Tree } from "~/components/TreeView/TreeView";-import { useRouteData } from "~/hooks";--import type { QuoteMethod } from "~/modules/sales";-import { QuoteBillOfMaterial, QuoteBillOfProcess } from "~/modules/sales";-import { path } from "~/utils/path";--export default function QuoteMakeMethodRoute() {- const { quoteId, lineId } = useParams();- if (!quoteId) throw new Error("Could not find quoteId");- if (!lineId) throw new Error("Could not find lineId");-- const quoteData = useRouteData<{ methods: Tree<QuoteMethod>[] }>(- path.to.quote(quoteId)- );-- const methodTree = quoteData?.methods?.find(- (m) => m.data.quoteLineId === lineId- );-- const quoteMakeMethodId = methodTree?.data.quoteMaterialMakeMethodId;- if (!quoteMakeMethodId) throw new Error("Could not find quoteMakeMethodId");-- return (- <VStack spacing={2} className="p-2">- <QuoteBillOfProcess- key={`bop:${quoteId}:${lineId}`}- quoteMakeMethodId={quoteMakeMethodId}- operations={[]}- />- <QuoteBillOfMaterial- key={`bom:${quoteId}:${lineId}`}- quoteMakeMethodId={quoteMakeMethodId}- materials={[]}- operations={[]}- />- </VStack>- );-}diff --git a/apps/carbon/app/routes/x+/quote+/methods.$quoteId.$lineId.operation.$id.tsx b/apps/carbon/app/routes/x+/quote+/methods.$quoteId.$lineId.operation.$id.tsxindex ff49ed5cf3..0d02432342 100644--- a/apps/carbon/app/routes/x+/quote+/methods.$quoteId.$lineId.operation.$id.tsx+++ b/apps/carbon/app/routes/x+/quote+/methods.$quoteId.$lineId.operation.$id.tsx@@ -1,9 +1,6 @@import { validationError, validator } from "@carbon/remix-validated-form";import { json, type ActionFunctionArgs } from "@remix-run/node";-import {- methodOperationValidator,- upsertMethodOperation,-} from "~/modules/items";+import { quoteOperationValidator, upsertQuoteOperation } from "~/modules/sales";import { requirePermissions } from "~/services/auth/auth.server";import { flash } from "~/services/session.server";import { setCustomFields } from "~/utils/form";@@ -16,16 +13,19 @@ export async function action({ request, params }: ActionFunctionArgs) {create: "parts",});- const { makeMethodId, id } = params;- if (!makeMethodId) {- throw new Error("makeMethodId not found");+ const { quoteId, lineId, id } = params;+ if (!quoteId) {+ throw new Error("quoteId not found");+ }+ if (!lineId) {+ throw new Error("lineId not found");}if (!id) {throw new Error("id not found");}const formData = await request.formData();- const validation = await validator(methodOperationValidator).validate(+ const validation = await validator(quoteOperationValidator).validate(formData);@@ -33,37 +33,39 @@ export async function action({ request, params }: ActionFunctionArgs) {return validationError(validation.error);}- const updateMethodOperation = await upsertMethodOperation(client, {+ const updateQuoteOperation = await upsertQuoteOperation(client, {+ quoteId,+ quoteLineId: lineId,...validation.data,id: id,companyId,updatedBy: userId,customFields: setCustomFields(formData),});- if (updateMethodOperation.error) {+ if (updateQuoteOperation.error) {return json({id: null,},await flash(request,- error(updateMethodOperation.error, "Failed to update method operation")+ error(updateQuoteOperation.error, "Failed to update quote operation")));}- const methodOperationId = updateMethodOperation.data?.id;- if (!methodOperationId) {+ const quoteOperationId = updateQuoteOperation.data?.id;+ if (!quoteOperationId) {return json({id: null,},await flash(request,- error(updateMethodOperation, "Failed to update method operation")+ error(updateQuoteOperation, "Failed to update quote operation")));}- return json({ id: methodOperationId });+ return json({ id: quoteOperationId });}diff --git a/apps/carbon/app/routes/x+/quote+/methods.$quoteId.$lineId.operation.new.tsx b/apps/carbon/app/routes/x+/quote+/methods.$quoteId.$lineId.operation.new.tsxindex 0e1ce24dc6..9ec5e4f28a 100644--- a/apps/carbon/app/routes/x+/quote+/methods.$quoteId.$lineId.operation.new.tsx+++ b/apps/carbon/app/routes/x+/quote+/methods.$quoteId.$lineId.operation.new.tsx@@ -47,23 +47,23 @@ export async function action({ request, params }: ActionFunctionArgs) {},await flash(request,- error(insertQuoteOperation.error, "Failed to insert method operation")+ error(insertQuoteOperation.error, "Failed to insert quote operation")));}- const methodOperationId = insertQuoteOperation.data?.id;- if (!methodOperationId) {+ const quoteOperationId = insertQuoteOperation.data?.id;+ if (!quoteOperationId) {return json({id: null,},await flash(request,- error(insertQuoteOperation, "Failed to insert method operation")+ error(insertQuoteOperation, "Failed to insert quote operation")));}- return json({ id: methodOperationId });+ return json({ id: quoteOperationId });}diff --git a/apps/carbon/app/utils/path.ts b/apps/carbon/app/utils/path.tsindex a3a7303fc1..6516084186 100644--- a/apps/carbon/app/utils/path.ts+++ b/apps/carbon/app/utils/path.ts@@ -588,8 +588,8 @@ export const path = {generatePath(`${x}/quote/${quoteId}/${lineId}/${makeMethodId}/${methodMaterialId}`),- quoteLineMethod: (quoteId: string, quoteLineId: string) =>- generatePath(`${x}/quote/${quoteId}/${quoteLineId}/method`),+ quoteLineMethod: (quoteId: string, quoteLineId: string, methodId: string) =>+ generatePath(`${x}/quote/${quoteId}/${quoteLineId}/method/${methodId}`),quoteOperation: (quoteId: string, lineId: string, id: string) =>generatePath(`${x}/quote/methods/${quoteId}/${lineId}/operation/${id}`),quoteOperationsOrder: `${x}/quote/methods/operation/order`,