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
updates to buyer section and address formatting
Gaurav Bhatt48eaef7299a7
diff --git a/apps/erp/app/modules/purchasing/purchasing.service.ts b/apps/erp/app/modules/purchasing/purchasing.service.tsindex 6b28c8e36c..5cadfd813b 100644--- a/apps/erp/app/modules/purchasing/purchasing.service.ts+++ b/apps/erp/app/modules/purchasing/purchasing.service.ts@@ -2269,18 +2269,9 @@ export async function getResolvedPoAttachments(supplierId: string | null;supplierInteractionId: string | null;itemIds: string[];- /** Filename of the freshly-generated PO PDF — excluded from ad-hoc listing- * since the action attaches it separately. */- excludePoPdfFileName?: string;}): Promise<ResolvedAttachment[]> {- const {- companyId,- supplierId,- supplierInteractionId,- itemIds,- excludePoPdfFileName- } = args;+ const { companyId, supplierId, supplierInteractionId, itemIds } = args;const companyPrefix = `${companyId}/default-attachments/company`;const supplierPrefix = supplierId@@ -2345,8 +2336,6 @@ export async function getResolvedPoAttachments(if (poPrefix) {for (const f of poFiles) {- // Skip the PO PDF we just generated — the action attaches it separately.- if (excludePoPdfFileName && f.name === excludePoPdfFileName) continue;const path = `${poPrefix}/${f.name}`;if (!byPath.has(path))byPath.set(path, {diff --git a/apps/erp/app/modules/resources/resources.models.ts b/apps/erp/app/modules/resources/resources.models.tsindex c9d1c66a25..35212df0da 100644--- a/apps/erp/app/modules/resources/resources.models.ts+++ b/apps/erp/app/modules/resources/resources.models.ts@@ -74,9 +74,7 @@ export const locationValidator = zaddressLine1: z.string().min(1, { message: "Address is required" }),addressLine2: z.string().optional(),city: z.string().min(1, { message: "City is required" }),- stateProvince: z- .string()- .min(1, { message: "State / Province is required" }),+ stateProvince: zfd.text(z.string().optional()),postalCode: z.string().min(1, { message: "Postal Code is required" }),countryCode: z.string().min(1, { message: "Country is required" }),timezone: z.string().min(1, { message: "Timezone is required" }),diff --git a/apps/erp/app/modules/settings/settings.models.ts b/apps/erp/app/modules/settings/settings.models.tsindex c63d3878ae..31302f1bb6 100644--- a/apps/erp/app/modules/settings/settings.models.ts+++ b/apps/erp/app/modules/settings/settings.models.ts@@ -63,7 +63,7 @@ const company = {addressLine1: z.string().min(1, { message: "Address is required" }),addressLine2: zfd.text(z.string().optional()),city: z.string().min(1, { message: "City is required" }),- stateProvince: z.string().min(1, { message: "State / Province is required" }),+ stateProvince: zfd.text(z.string().optional()),postalCode: z.string().min(1, { message: "Postal Code is required" }),countryCode: z.string().min(1, { message: "Country is required" }),baseCurrencyCode: zfd.text(z.string()),diff --git a/apps/erp/app/routes/api+/mcp+/lib/tool-metadata.json b/apps/erp/app/routes/api+/mcp+/lib/tool-metadata.jsonindex eb77e42c72..f9d0caf0c9 100644--- a/apps/erp/app/routes/api+/mcp+/lib/tool-metadata.json+++ b/apps/erp/app/routes/api+/mcp+/lib/tool-metadata.json@@ -1,5 +1,5 @@{- "generated": "2026-05-22T05:14:46.487Z",+ "generated": "2026-05-25T08:26:21.811Z","totalTools": 1075,"modules": 15,"tools": [diff --git a/apps/erp/app/routes/x+/purchase-order+/$orderId.finalize.tsx b/apps/erp/app/routes/x+/purchase-order+/$orderId.finalize.tsxindex 445face6ae..6431755db7 100644--- a/apps/erp/app/routes/x+/purchase-order+/$orderId.finalize.tsx+++ b/apps/erp/app/routes/x+/purchase-order+/$orderId.finalize.tsx@@ -349,22 +349,9 @@ export async function action(args: ActionFunctionArgs) {const html = await renderAsync(emailTemplate);const text = await renderAsync(emailTemplate, { plainText: true });- const signedMainPdf = await serviceRole.storage- .from("private")- .createSignedUrl(documentFilePath, 3600);- if (signedMainPdf.error || !signedMainPdf.data?.signedUrl) {- console.error(`${logPrefix} failed to sign main PO PDF`, {- path: documentFilePath,- error: signedMainPdf.error- });- } else {- console.log(`${logPrefix} signed main PO PDF`, {- path: documentFilePath- });- }- const signedUrlData = signedMainPdf.data;-// Resolve cascaded attachments (Company + Supplier + Item + PO ad-hoc).+ // The freshly-uploaded PO PDF is in supplier-interaction/ and rides+ // along naturally as a `po`-source file in the cascade.const itemIds = Array.from(new Set((purchaseOrderLines.data ?? [])@@ -377,8 +364,7 @@ export async function action(args: ActionFunctionArgs) {supplierId: purchaseOrder.data.supplierId ?? null,supplierInteractionId:purchaseOrder.data.supplierInteractionId ?? null,- itemIds,- excludePoPdfFileName: fileName+ itemIds});console.log(`${logPrefix} resolved cascaded attachments`, {total: resolved.length,@@ -434,14 +420,7 @@ export async function action(args: ActionFunctionArgs) {successful: cascadedAttachments.length});- const allAttachments: { path: string; filename: string }[] = [];- if (signedUrlData?.signedUrl) {- allAttachments.push({- path: signedUrlData.signedUrl,- filename: fileName- });- }- allAttachments.push(...cascadedAttachments);+ const allAttachments = cascadedAttachments;const triggerPayload = {to: [buyer.data.email, supplier.data.contact.email],diff --git a/packages/database/supabase/migrations/20260525000000_purchase-orders-view-buyer.sql b/packages/database/supabase/migrations/20260525000000_purchase-orders-view-buyer.sqlnew file mode 100644index 0000000000..d792859f51--- /dev/null+++ b/packages/database/supabase/migrations/20260525000000_purchase-orders-view-buyer.sql@@ -0,0 +1,54 @@+-- Expose the assignee and supplier-account-manager user details on the+-- purchaseOrders view so the PO PDF can pick a buyer contact in priority order:+-- assignee → supplier.accountManager → createdBy.++DROP VIEW IF EXISTS "purchaseOrders";+CREATE OR REPLACE VIEW "purchaseOrders" WITH(SECURITY_INVOKER=true) AS+ SELECT+ p.*,+ pl."thumbnailPath",+ pl."itemType",+ pl."orderTotal" + pd."supplierShippingCost" * p."exchangeRate" AS "orderTotal",+ pd."shippingMethodId",+ pd."shippingTermId",+ pd."receiptRequestedDate",+ pd."receiptPromisedDate",+ pd."deliveryDate",+ pd."dropShipment",+ pp."paymentTermId",+ pd."locationId",+ pd."supplierShippingCost",+ pd."incoterm",+ pd."incotermLocation",+ u."fullName" AS "createdByFullName",+ u."email" AS "createdByEmail",+ u."phone" AS "createdByPhone",+ ua."fullName" AS "assigneeFullName",+ ua."email" AS "assigneeEmail",+ ua."phone" AS "assigneePhone",+ uam."fullName" AS "accountManagerFullName",+ uam."email" AS "accountManagerEmail",+ uam."phone" AS "accountManagerPhone"+ FROM "purchaseOrder" p+ LEFT JOIN (+ SELECT+ pol."purchaseOrderId",+ MIN(CASE+ WHEN i."thumbnailPath" IS NULL AND mu."thumbnailPath" IS NOT NULL THEN mu."thumbnailPath"+ ELSE i."thumbnailPath"+ END) AS "thumbnailPath",+ SUM(COALESCE(pol."purchaseQuantity", 0)*(COALESCE(pol."unitPrice", 0)) + COALESCE(pol."shippingCost", 0) + COALESCE(pol."taxAmount", 0)) AS "orderTotal",+ MIN(i."type") AS "itemType"+ FROM "purchaseOrderLine" pol+ LEFT JOIN "item" i+ ON i."id" = pol."itemId"+ LEFT JOIN "modelUpload" mu ON mu.id = i."modelUploadId"+ GROUP BY pol."purchaseOrderId"+ ) pl ON pl."purchaseOrderId" = p."id"+ LEFT JOIN "purchaseOrderDelivery" pd ON pd."id" = p."id"+ LEFT JOIN "shippingTerm" st ON st."id" = pd."shippingTermId"+ LEFT JOIN "purchaseOrderPayment" pp ON pp."id" = p."id"+ LEFT JOIN "user" u ON u."id" = p."createdBy"+ LEFT JOIN "user" ua ON ua."id" = p."assignee"+ LEFT JOIN "supplier" s ON s."id" = p."supplierId"+ LEFT JOIN "user" uam ON uam."id" = s."accountManagerId";diff --git a/packages/database/supabase/migrations/20260525000100_location-state-optional.sql b/packages/database/supabase/migrations/20260525000100_location-state-optional.sqlnew file mode 100644index 0000000000..e9efc85f1d--- /dev/null+++ b/packages/database/supabase/migrations/20260525000100_location-state-optional.sql@@ -0,0 +1,6 @@+-- Make stateProvince optional on `location` to match the validator change.+-- Many countries (UK, IE, JP, most EU, SG) have no state concept, so this+-- column must accept NULL. The `company` and `address` tables already allow+-- NULL — only `location` had the NOT NULL constraint.++ALTER TABLE "location" ALTER COLUMN "stateProvince" DROP NOT NULL;diff --git a/packages/documents/src/pdf/PackingSlipPDF.tsx b/packages/documents/src/pdf/PackingSlipPDF.tsxindex 4b806a8e37..215c365379 100644--- a/packages/documents/src/pdf/PackingSlipPDF.tsx+++ b/packages/documents/src/pdf/PackingSlipPDF.tsx@@ -2,7 +2,7 @@ import bwipjs from "@bwip-js/node";import type { Database } from "@carbon/database";import type { JSONContent } from "@carbon/react";import type { TrackedEntityAttributes } from "@carbon/utils";-import { formatCityStatePostalCode, formatDate } from "@carbon/utils";+import { formatDate } from "@carbon/utils";import { Image, Text, View } from "@react-pdf/renderer";import { createTw } from "react-pdf-tailwind";import { generateQRCode } from "../qr/qr-code";@@ -115,9 +115,10 @@ const PackingSlipPDF = ({)}{addressLine1 && <Text style={tw("mt-1")}>{addressLine1}</Text>}{addressLine2 && <Text>{addressLine2}</Text>}- {(city || stateProvince || postalCode) && (+ {city && <Text>{city}</Text>}+ {(stateProvince || postalCode) && (<Text>- {formatCityStatePostalCode(city, stateProvince, postalCode)}+ {[stateProvince, postalCode].filter(Boolean).join(" ")}</Text>)}{countryCode && <Text>{countryCode}</Text>}diff --git a/packages/documents/src/pdf/PurchaseOrderPDF.tsx b/packages/documents/src/pdf/PurchaseOrderPDF.tsxindex fabf479abe..7c25dc3749 100644--- a/packages/documents/src/pdf/PurchaseOrderPDF.tsx+++ b/packages/documents/src/pdf/PurchaseOrderPDF.tsx@@ -77,6 +77,7 @@ const PurchaseOrderPDF = ({supplierStateProvince,supplierPostalCode,supplierCountryCode,+ supplierCountryName,deliveryName,deliveryAddressLine1,deliveryAddressLine2,@@ -84,6 +85,7 @@ const PurchaseOrderPDF = ({deliveryStateProvince,deliveryPostalCode,deliveryCountryCode,+ deliveryCountryName,dropShipment,customerName,customerAddressLine1,@@ -91,7 +93,8 @@ const PurchaseOrderPDF = ({customerCity,customerStateProvince,customerPostalCode,- customerCountryCode+ customerCountryCode,+ customerCountryName} = purchaseOrderLocations;const currencyCode =@@ -121,7 +124,7 @@ const PurchaseOrderPDF = ({city: customerCity,stateProvince: customerStateProvince,postalCode: customerPostalCode,- countryCode: customerCountryCode+ country: customerCountryName ?? customerCountryCode}: {name: deliveryName,@@ -130,7 +133,7 @@ const PurchaseOrderPDF = ({city: deliveryCity,stateProvince: deliveryStateProvince,postalCode: deliveryPostalCode,- countryCode: deliveryCountryCode+ country: deliveryCountryName ?? deliveryCountryCode};const headerTitle = purchaseOrder?.purchaseOrderId@@ -199,7 +202,7 @@ const PurchaseOrderPDF = ({city={supplierCity}stateProvince={supplierStateProvince}postalCode={supplierPostalCode}- countryCode={supplierCountryCode}+ country={supplierCountryName ?? supplierCountryCode}/>{purchaseOrderLocations.supplierTaxId &&!isEoriCountry(supplierCountryCode) && (@@ -281,20 +284,36 @@ const PurchaseOrderPDF = ({<View style={tw("h-[1px] bg-gray-200 my-2")} /><View style={tw("text-[9px] text-gray-800")}>{company.vatNumber && <Text>VAT: {company.vatNumber}</Text>}- {purchaseOrder.createdByFullName && (- <Text>Contact: {purchaseOrder.createdByFullName}</Text>- )}- {purchaseOrder.createdByEmail && (- <Text>Email: {purchaseOrder.createdByEmail}</Text>- )}- {purchaseOrder.createdByPhone && (- <Text>Phone: {purchaseOrder.createdByPhone}</Text>- )}+ {(() => {+ const name =+ purchaseOrder.assigneeFullName ??+ purchaseOrder.accountManagerFullName ??+ purchaseOrder.createdByFullName;+ const email =+ purchaseOrder.assigneeEmail ??+ purchaseOrder.accountManagerEmail ??+ purchaseOrder.createdByEmail;+ const phone =+ purchaseOrder.assigneePhone ??+ purchaseOrder.accountManagerPhone ??+ purchaseOrder.createdByPhone;+ return (+ <>+ {name && <Text>Contact: {name}</Text>}+ {email && <Text>Email: {email}</Text>}+ {phone && <Text>Phone: {phone}</Text>}+ </>+ );+ })()}{accountsPayableBillingAddress?.email && (- <Text style={tw("font-bold")}>- Billing documents and enquiries to:{" "}- {accountsPayableBillingAddress.email}- </Text>+ <>+ <Text style={tw("font-bold mt-1")}>+ Billing documents and enquiries:+ </Text>+ <Text style={tw("font-bold")}>+ {accountsPayableBillingAddress.email}+ </Text>+ </>)}</View></View>diff --git a/packages/documents/src/pdf/QuotePDF.tsx b/packages/documents/src/pdf/QuotePDF.tsxindex 2ca5db453d..e73daba76d 100644--- a/packages/documents/src/pdf/QuotePDF.tsx+++ b/packages/documents/src/pdf/QuotePDF.tsx@@ -78,6 +78,7 @@ const QuotePDF = ({customerStateProvince,customerPostalCode,customerCountryCode,+ customerCountryName,customerTaxId,customerVatNumber,customerEori,@@ -97,8 +98,7 @@ const QuotePDF = ({const registrationLine = composeRegistrationLine({companyName: company.name,country: company.countryCode,- eori: company.eori,- accountsReceivableEmail: companySettings?.accountsReceivableEmail+ eori: company.eori});const pricesByLine = quoteLinePrices.reduce<@@ -293,7 +293,7 @@ const QuotePDF = ({city={customerCity}stateProvince={customerStateProvince}postalCode={customerPostalCode}- countryCode={customerCountryCode}+ country={customerCountryName ?? customerCountryCode}/>{customerTaxId && !isEoriCountry(customerCountryCode) && (<Text>Tax ID: {customerTaxId}</Text>diff --git a/packages/documents/src/pdf/SalesInvoicePDF.tsx b/packages/documents/src/pdf/SalesInvoicePDF.tsxindex 7a764dad08..8ee7bb1db4 100644--- a/packages/documents/src/pdf/SalesInvoicePDF.tsx+++ b/packages/documents/src/pdf/SalesInvoicePDF.tsx@@ -107,8 +107,7 @@ const SalesInvoicePDF = ({const registrationLine = composeRegistrationLine({companyName: company.name,country: company.countryCode,- eori: company.eori,- accountsReceivableEmail: companySettings?.accountsReceivableEmail+ eori: company.eori});const paymentTerm = paymentTerms?.find(@@ -177,7 +176,7 @@ const SalesInvoicePDF = ({city={invoiceCity ?? customerCity}stateProvince={invoiceStateProvince ?? customerStateProvince}postalCode={invoicePostalCode ?? customerPostalCode}- countryCode={invoiceCountryName ?? customerCountryName}+ country={invoiceCountryName ?? customerCountryName}/>{customerTaxId &&!isEoriCountry(invoiceCountryName ?? customerCountryName) && (@@ -253,7 +252,7 @@ const SalesInvoicePDF = ({city={shipmentCity}stateProvince={shipmentStateProvince}postalCode={shipmentPostalCode}- countryCode={shipmentCountryName}+ country={shipmentCountryName}/></View></View>diff --git a/packages/documents/src/pdf/SalesOrderPDF.tsx b/packages/documents/src/pdf/SalesOrderPDF.tsxindex d127330a76..46261894a0 100644--- a/packages/documents/src/pdf/SalesOrderPDF.tsx+++ b/packages/documents/src/pdf/SalesOrderPDF.tsx@@ -98,8 +98,7 @@ const SalesOrderPDF = ({const registrationLine = composeRegistrationLine({companyName: company.name,country: company.countryCode,- eori: company.eori,- accountsReceivableEmail: companySettings?.accountsReceivableEmail+ eori: company.eori});const paymentTerm = paymentTerms?.find(@@ -168,7 +167,7 @@ const SalesOrderPDF = ({city={customerCity}stateProvince={customerStateProvince}postalCode={customerPostalCode}- countryCode={customerCountryName}+ country={customerCountryName}/>{customerTaxId && !isEoriCountry(customerCountryName) && (<Text>Tax ID: {customerTaxId}</Text>@@ -254,7 +253,7 @@ const SalesOrderPDF = ({city={paymentCity}stateProvince={paymentStateProvince}postalCode={paymentPostalCode}- countryCode={paymentCountryName}+ country={paymentCountryName}/></View></View>diff --git a/packages/documents/src/pdf/components/AddressBlock.tsx b/packages/documents/src/pdf/components/AddressBlock.tsxindex 24ff809e1d..bc8b6bcbbb 100644--- a/packages/documents/src/pdf/components/AddressBlock.tsx+++ b/packages/documents/src/pdf/components/AddressBlock.tsx@@ -1,4 +1,3 @@-import { formatCityStatePostalCode } from "@carbon/utils";import { Text } from "@react-pdf/renderer";import { createTw } from "react-pdf-tailwind";@@ -9,7 +8,7 @@ type AddressBlockProps = {city?: string | null;stateProvince?: string | null;postalCode?: string | null;- countryCode?: string | null;+ country?: string | null;};const tw = createTw({@@ -33,24 +32,17 @@ const AddressBlock = ({city,stateProvince,postalCode,- countryCode+ country}: AddressBlockProps) => {- const hasCityRow = city || stateProvince || postalCode || countryCode;+ const stateAndPostal = [stateProvince, postalCode].filter(Boolean).join(" ");return (<>{name && <Text style={tw("font-bold")}>{name}</Text>}{addressLine1 && <Text>{addressLine1}</Text>}{addressLine2 && <Text>{addressLine2}</Text>}- {hasCityRow && (- <Text>- {[- formatCityStatePostalCode(city, stateProvince, postalCode),- countryCode- ]- .filter(Boolean)- .join(" ")}- </Text>- )}+ {city && <Text>{city}</Text>}+ {stateAndPostal && <Text>{stateAndPostal}</Text>}+ {country && <Text>{country}</Text>}</>);};diff --git a/packages/documents/src/pdf/components/Header.tsx b/packages/documents/src/pdf/components/Header.tsxindex b3fd9fcaec..9e4c1b30f8 100644--- a/packages/documents/src/pdf/components/Header.tsx+++ b/packages/documents/src/pdf/components/Header.tsx@@ -56,21 +56,13 @@ const Header = ({ company, title, documentId, fixed }: HeaderProps) => {{company.name && <Text style={tw("font-bold")}>{company.name}</Text>}{company.addressLine1 && <Text>{company.addressLine1}</Text>}{company.addressLine2 && <Text>{company.addressLine2}</Text>}- {(company.city ||- company.stateProvince ||- company.postalCode ||- company.countryCode) && (+ {(company.city || company.stateProvince || company.postalCode) && (<Text>- {[- formatCityStatePostalCode(- company.city,- company.stateProvince,- company.postalCode- ),- company.countryCode- ]- .filter(Boolean)- .join(" ")}+ {formatCityStatePostalCode(+ company.city,+ company.stateProvince,+ company.postalCode+ )}</Text>)}</View>diff --git a/packages/documents/src/pdf/components/Summary.tsx b/packages/documents/src/pdf/components/Summary.tsxindex 3d2b7e4e4e..d209f3d19f 100644--- a/packages/documents/src/pdf/components/Summary.tsx+++ b/packages/documents/src/pdf/components/Summary.tsx@@ -62,8 +62,13 @@ const Summary = ({ company, items }: SummaryProps) => {<Text style={styles.companyName}>{company.name}</Text>{company.addressLine1 && <Text>{company.addressLine1}</Text>}{company.addressLine2 && <Text>{company.addressLine2}</Text>}- {company.city && company.stateProvince && company.postalCode && (- <Text>{`${company.city}, ${company.stateProvince}, ${company.postalCode}`}</Text>+ {company.city && <Text>{company.city}</Text>}+ {(company.stateProvince || company.postalCode) && (+ <Text>+ {[company.stateProvince, company.postalCode]+ .filter(Boolean)+ .join(" ")}+ </Text>)}{company.phone && <Text>Phone: {company.phone}</Text>}{company.email && <Text>Email: {company.email}</Text>}diff --git a/packages/documents/src/utils/footer.ts b/packages/documents/src/utils/footer.tsindex 4c815f81ac..a7037472af 100644--- a/packages/documents/src/utils/footer.ts+++ b/packages/documents/src/utils/footer.ts@@ -13,18 +13,14 @@export function composeRegistrationLine({companyName,country,- eori,- accountsReceivableEmail+ eori}: {companyName: string | null | undefined;country: string | null | undefined;eori?: string | null;- accountsReceivableEmail?: string | null;}): string | null {if (!companyName || !country) return null;let line = `${companyName} is registered in ${country}`;- if (eori) line += `, Company Number ${eori}`;- if (accountsReceivableEmail)- line += ` · Accounts Receivable: ${accountsReceivableEmail}`;+ if (eori) line += `, Company Registration Number ${eori}`;return line;}diff --git a/packages/documents/src/utils/shared.ts b/packages/documents/src/utils/shared.tsindex afb9317b4c..abae7e7aa1 100644--- a/packages/documents/src/utils/shared.ts+++ b/packages/documents/src/utils/shared.ts@@ -19,7 +19,7 @@ export const getRegistrationFooter = (if (!name) return undefined;const country = getCountryName(countryCode);const base = country ? `${name} is registered in ${country}` : name;- return taxId ? `${base}, Company Number ${taxId}` : base;+ return taxId ? `${base}, Company Registration Number ${taxId}` : base;};export const formatTaxPercent = (