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: force locationId if one doesn't exist
Brad Barbin79281db62d93
diff --git a/apps/erp/app/modules/production/production.service.ts b/apps/erp/app/modules/production/production.service.tsindex b7bd22d2ed..00918d6243 100644--- a/apps/erp/app/modules/production/production.service.ts+++ b/apps/erp/app/modules/production/production.service.ts@@ -131,6 +131,32 @@ export async function convertSalesOrderLinesToJobs(const dueDate = line.promisedDate ?? undefined;+ // Validate locationId exists if provided+ let locationId = line.locationId;+ if (locationId) {+ const locationExists = await serviceRole+ .from("location")+ .select("id")+ .eq("id", locationId)+ .eq("companyId", companyId)+ .single();++ if (locationExists.error) {+ // If location doesn't exist, try to get a default location for the company+ const defaultLocation = await serviceRole+ .from("location")+ .select("id")+ .eq("companyId", companyId)+ .limit(1);++ if (defaultLocation.data) {+ locationId = defaultLocation.data?.[0]?.id;+ } else {+ throw new Error("No location found");+ }+ }+ }+const data = {customerId: salesOrder.data?.customerId ?? undefined,deadlineType: "Hard Deadline" as const,@@ -141,7 +167,7 @@ export async function convertSalesOrderLinesToJobs(.toString(): undefined,itemId: line.itemId,- locationId: line.locationId ?? "",+ locationId: locationId!,modelUploadId: line.modelUploadId ?? undefined,quantity: jobQuantity,quoteId: quoteId ?? undefined,