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: don't allow configured parts to be overwritten by a save method
Brad Barbina3fd123e7278
diff --git a/apps/erp/app/routes/x+/part+/$itemId.manufacturing.$methodId.method.tsx b/apps/erp/app/routes/x+/part+/$itemId.manufacturing.$methodId.method.tsxindex 5e7a349e13..291f25bb6c 100644--- a/apps/erp/app/routes/x+/part+/$itemId.manufacturing.$methodId.method.tsx+++ b/apps/erp/app/routes/x+/part+/$itemId.manufacturing.$methodId.method.tsx@@ -47,7 +47,7 @@ export async function loader({ request, params }: LoaderFunctionArgs) {export async function action({ request, params }: ActionFunctionArgs) {assertIsPost(request);- const { client, companyId, userId } = await requirePermissions(request, {+ const { client, userId } = await requirePermissions(request, {update: "parts",});@@ -61,11 +61,13 @@ export async function action({ request, params }: ActionFunctionArgs) {);if (validation.error) {+ console.error(validation.error);return validationError(validation.error);}const updatePartManufacturing = await upsertItemManufacturing(client, {...validation.data,+ requiresConfiguration: validation.data.requiresConfiguration ?? false,itemId,updatedBy: userId,customFields: setCustomFields(formData),diff --git a/packages/database/supabase/functions/get-method/index.ts b/packages/database/supabase/functions/get-method/index.tsindex 3876c48b23..fc5d9ac285 100644--- a/packages/database/supabase/functions/get-method/index.ts+++ b/packages/database/supabase/functions/get-method/index.ts@@ -89,24 +89,39 @@ serve(async (req: Request) => {switch (type) {case "itemToItem": {- const [sourceMakeMethod, targetMakeMethod] = await Promise.all([- client- .from("activeMakeMethods")- .select("*")- .eq("itemId", sourceId)- .eq("companyId", companyId)- .single(),- client- .from("activeMakeMethods")- .select("*")- .eq("itemId", targetId)- .eq("companyId", companyId)- .single(),- ]);+ const [sourceMakeMethod, targetMakeMethod, targetItemReplenishment] =+ await Promise.all([+ client+ .from("activeMakeMethods")+ .select("*")+ .eq("itemId", sourceId)+ .eq("companyId", companyId)+ .single(),+ client+ .from("activeMakeMethods")+ .select("*")+ .eq("itemId", targetId)+ .eq("companyId", companyId)+ .single(),+ client+ .from("itemReplenishment")+ .select("*")+ .eq("itemId", targetId)+ .eq("companyId", companyId)+ .single(),+ ]);if (sourceMakeMethod.error || targetMakeMethod.error) {throw new Error("Failed to get make methods");}+ if (targetItemReplenishment.error) {+ throw new Error("Failed to get target item replenishment");+ }++ if (targetItemReplenishment.data?.requiresConfiguration) {+ throw new Error("Cannot override method of configured item");+ }+if (sourceMakeMethod.data.id === null ||targetMakeMethod.data.id === null@@ -2020,7 +2035,7 @@ serve(async (req: Request) => {const itemId = makeMethod.data?.itemId;- const [jobOperations] = await Promise.all([+ const [jobOperations, itemReplenishment] = await Promise.all([client.from("jobOperationsWithMakeMethods").select(@@ -2028,12 +2043,26 @@ serve(async (req: Request) => {).eq("jobId", jobMakeMethod.data.jobId).eq("companyId", companyId),+ client+ .from("itemReplenishment")+ .select("*")+ .eq("itemId", itemId)+ .eq("companyId", companyId)+ .single(),]);if (jobOperations.error) {throw new Error("Failed to get job operations");}+ if (itemReplenishment.error) {+ throw new Error("Failed to get item replenishment");+ }++ if (itemReplenishment.data?.requiresConfiguration) {+ throw new Error("Cannot override method of configured item");+ }+const [jobMethodTrees] = await Promise.all([getJobMethodTree(client,@@ -2305,10 +2334,24 @@ serve(async (req: Request) => {const itemId = makeMethod.data?.itemId;- const [jobMethodTrees] = await Promise.all([+ const [jobMethodTrees, itemReplenishment] = await Promise.all([getJobMethodTree(client, jobMakeMethod.data.id),+ client+ .from("itemReplenishment")+ .select("*")+ .eq("itemId", itemId)+ .eq("companyId", companyId)+ .single(),]);+ if (itemReplenishment.error) {+ throw new Error("Failed to get item replenishment");+ }++ if (itemReplenishment.data?.requiresConfiguration) {+ throw new Error("Cannot override method of configured item");+ }+if (jobMethodTrees.error) {throw new Error("Failed to get method tree");}@@ -2867,14 +2910,28 @@ serve(async (req: Request) => {const itemId = makeMethod.data?.itemId;- const [quoteMethodTrees] = await Promise.all([+ const [quoteMethodTrees, itemReplenishment] = await Promise.all([getQuoteMethodTree(client, quoteMakeMethod.data.id),+ client+ .from("itemReplenishment")+ .select("*")+ .eq("itemId", itemId)+ .eq("companyId", companyId)+ .single(),]);if (quoteMethodTrees.error) {throw new Error("Failed to get method tree");}+ if (itemReplenishment.error) {+ throw new Error("Failed to get item replenishment");+ }++ if (itemReplenishment.data?.requiresConfiguration) {+ throw new Error("Cannot override method of configured item");+ }+const quoteMethodTree = quoteMethodTrees.data?.[0] as QuoteMethodTreeItem;if (!quoteMethodTree) throw new Error("Method tree not found");@@ -3126,7 +3183,7 @@ serve(async (req: Request) => {const itemId = makeMethod.data?.itemId;- const [quoteOperations] = await Promise.all([+ const [quoteOperations, itemReplenishment] = await Promise.all([client.from("quoteOperationsWithMakeMethods").select(@@ -3134,12 +3191,26 @@ serve(async (req: Request) => {).eq("quoteLineId", quoteMakeMethod.data.quoteLineId).eq("companyId", companyId),+ client+ .from("itemReplenishment")+ .select("*")+ .eq("itemId", itemId)+ .eq("companyId", companyId)+ .single(),]);if (quoteOperations.error) {throw new Error("Failed to get quote operations");}+ if (itemReplenishment.error) {+ throw new Error("Failed to get item replenishment");+ }++ if (itemReplenishment.data?.requiresConfiguration) {+ throw new Error("Cannot override method of configured item");+ }+const [quoteMethodTrees] = await Promise.all([getQuoteMethodTree(client,