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: ensure quote has a location for paperless integration
Brad Barbindd876e6a719c
diff --git a/packages/ee/src/paperless-parts/lib/lib.ts b/packages/ee/src/paperless-parts/lib/lib.tsindex d159e28568..0ef4094085 100644--- a/packages/ee/src/paperless-parts/lib/lib.ts+++ b/packages/ee/src/paperless-parts/lib/lib.ts@@ -1692,7 +1692,8 @@ export async function getOrderLocationId(const locations = await carbon.from("location").select("id, name")- .eq("companyId", company.id);+ .eq("companyId", company.id)+ .order("createdAt", { ascending: true });if (sendFrom) {const location = locations.data?.find(@@ -1704,15 +1705,10 @@ export async function getOrderLocationId(return location.id;}}- if (locations.data && locations.data.length > 0 && locations.data[0]?.id) {- return locations.data[0]?.id ?? null;- }- const hq = locations.data?.filter((location) =>- location.name?.toLowerCase().includes("headquarters")- );- if (hq && hq.length > 0) {- return hq[0]?.id ?? null;+ // Fallback to the first created location+ if (locations.data && locations.data.length > 0 && locations.data[0]?.id) {+ return locations.data[0].id;}return null;diff --git a/packages/jobs/trigger/paperless-parts.ts b/packages/jobs/trigger/paperless-parts.tsindex d19f951081..c435a4e55e 100644--- a/packages/jobs/trigger/paperless-parts.ts+++ b/packages/jobs/trigger/paperless-parts.ts@@ -227,6 +227,7 @@ export const paperlessPartsTask = task({customerContactId: quoteCustomerContactId,},{ createdBy: quoteCreatedBy },+ quoteLocationId,] = await Promise.all([getCustomerIdAndContactId(carbon, paperless, {company: company.data,@@ -237,6 +238,10 @@ export const paperlessPartsTask = task({estimator: ppQuote.data.estimator,salesPerson: ppQuote.data.salesperson,}),+ getOrderLocationId(carbon, {+ company: company.data,+ sendFrom: ppQuote.data.send_from_facility,+ }),]);if (!quoteCustomerId) {@@ -281,23 +286,18 @@ export const paperlessPartsTask = task({},};- const [- quoteCustomerPayment,- quoteCustomerShipping,- quoteEmployee,- quoteOpportunity,- ] = await Promise.all([- getCustomerPayment(carbon, quote.customerId),- getCustomerShipping(carbon, quote.customerId),- getEmployeeJob(carbon, quote.createdBy, quote.companyId),- carbon- .from("opportunity")- .insert([- { companyId: quote.companyId, customerId: quote.customerId },- ])- .select("id")- .single(),- ]);+ const [quoteCustomerPayment, quoteCustomerShipping, quoteOpportunity] =+ await Promise.all([+ getCustomerPayment(carbon, quote.customerId),+ getCustomerShipping(carbon, quote.customerId),+ carbon+ .from("opportunity")+ .insert([+ { companyId: quote.companyId, customerId: quote.customerId },+ ])+ .select("id")+ .single(),+ ]);if (quoteCustomerPayment.error) return quoteCustomerPayment;if (quoteCustomerShipping.error) return quoteCustomerShipping;@@ -329,7 +329,6 @@ export const paperlessPartsTask = task({quote.exchangeRateUpdatedAt = new Date().toISOString();}- const quoteLocationId = quoteEmployee?.data?.locationId ?? null;const insert = await carbon.from("quote").insert([@@ -782,19 +781,6 @@ async function getCustomerShipping(.single();}-async function getEmployeeJob(- client: SupabaseClient<Database>,- employeeId: string,- companyId: string-) {- return client- .from("employeeJob")- .select("*")- .eq("id", employeeId)- .eq("companyId", companyId)- .single();-}-async function getCurrencyByCode(client: SupabaseClient<Database>,companyId: string,