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: add supplier part number to purchase order line
Gaurav Bhatte0e6e3c17ea0
diff --git a/apps/erp/app/modules/purchasing/purchasing.models.ts b/apps/erp/app/modules/purchasing/purchasing.models.tsindex 093f21410e..0d821d501a 100644--- a/apps/erp/app/modules/purchasing/purchasing.models.ts+++ b/apps/erp/app/modules/purchasing/purchasing.models.ts@@ -228,6 +228,7 @@ export const purchaseOrderLineValidator = zpurchaseUnitOfMeasureCode: zfd.text(z.string().optional()),requiredDate: zfd.text(z.string().optional()),storageUnitId: zfd.text(z.string().optional()),+ supplierPartId: zfd.text(z.string().optional()),supplierShippingCost: zfd.numeric(z.number().optional()),supplierTaxAmount: zfd.numeric(z.number().optional()),supplierUnitPrice: zfd.numeric(z.number().optional())diff --git a/apps/erp/app/modules/purchasing/ui/PurchaseOrder/PurchaseOrderLineForm.tsx b/apps/erp/app/modules/purchasing/ui/PurchaseOrder/PurchaseOrderLineForm.tsxindex 905ac74779..5873787dbb 100644--- a/apps/erp/app/modules/purchasing/ui/PurchaseOrder/PurchaseOrderLineForm.tsx+++ b/apps/erp/app/modules/purchasing/ui/PurchaseOrder/PurchaseOrderLineForm.tsx@@ -119,6 +119,7 @@ const PurchaseOrderLineForm = ({purchaseUom: string;requiredDate: string | null;storageUnitId: string | null;+ supplierPartId: string;supplierShippingCost: number;supplierTaxAmount: number;supplierUnitPrice: number;@@ -135,6 +136,7 @@ const PurchaseOrderLineForm = ({priceBreaks: [],requiredDate: initialValues?.requiredDate ?? null,storageUnitId: initialValues.storageUnitId ?? "",+ supplierPartId: initialValues.supplierPartId ?? "",supplierShippingCost: initialValues.supplierShippingCost ?? 0,supplierTaxAmount: initialValues.supplierTaxAmount ?? 0,supplierUnitPrice: initialValues.supplierUnitPrice ?? 0,@@ -314,6 +316,7 @@ const PurchaseOrderLineForm = ({purchaseUom: "",requiredDate: null,storageUnitId: "",+ supplierPartId: "",supplierShippingCost: 0,supplierTaxAmount: 0,supplierUnitPrice: 0,@@ -395,6 +398,7 @@ const PurchaseOrderLineForm = ({? null: today(getLocalTimeZone()).add({ days: leadTime }).toString(),storageUnitId: inventory.data?.defaultStorageUnitId ?? null,+ supplierPartId: supplierPart?.data?.supplierPartId ?? "",supplierTaxAmount: 0,taxPercent: 0,priceBreaks: breaks,@@ -588,6 +592,18 @@ const PurchaseOrderLineForm = ({isOptional={false}/>+ <InputControlled+ name="supplierPartId"+ label={t`Supplier Part Number`}+ value={itemData.supplierPartId}+ onChange={(value) =>+ setItemData((d) => ({+ ...d,+ supplierPartId: value+ }))+ }+ />+{isOutsideProcessing && (<JobOperationSelect jobId={initialValues.jobId} />)}diff --git a/apps/erp/app/routes/x+/purchase-order+/$orderId.$lineId.details.tsx b/apps/erp/app/routes/x+/purchase-order+/$orderId.$lineId.details.tsxindex 29d6412c50..78de5cda65 100644--- a/apps/erp/app/routes/x+/purchase-order+/$orderId.$lineId.details.tsx+++ b/apps/erp/app/routes/x+/purchase-order+/$orderId.$lineId.details.tsx@@ -165,6 +165,7 @@ export default function EditPurchaseOrderLineRoute() {purchaseUnitOfMeasureCode: line?.purchaseUnitOfMeasureCode ?? "",requiredDate: line?.requiredDate ?? undefined,storageUnitId: line?.storageUnitId ?? "",+ supplierPartId: line?.supplierPartId ?? "",supplierShippingCost: line?.supplierShippingCost ?? 0,supplierTaxAmount: line?.supplierTaxAmount ?? 0,supplierUnitPrice: line?.supplierUnitPrice ?? 0,diff --git a/packages/database/supabase/migrations/20260529120000_purchase-order-line-supplier-part.sql b/packages/database/supabase/migrations/20260529120000_purchase-order-line-supplier-part.sqlnew file mode 100644index 0000000000..43cd39ca37--- /dev/null+++ b/packages/database/supabase/migrations/20260529120000_purchase-order-line-supplier-part.sql@@ -0,0 +1,66 @@+-- Make the purchase order line's supplier part number a real, line-level value.+--+-- Previously the `purchaseOrderLines` view derived `supplierPartId` by joining the+-- `supplierPart` master on (purchaseOrder.supplierId, item.id). That made the value+-- read-only, un-clearable, and impossible to override per line. We now store it on+-- the line itself, backfill from the old derivation so existing PDFs don't regress,+-- and rebuild the view to read the stored column instead of the join.++----------------------------------------------------------------------------+-- 1. Add the column+----------------------------------------------------------------------------+ALTER TABLE "purchaseOrderLine" ADD COLUMN "supplierPartId" TEXT;++----------------------------------------------------------------------------+-- 2. Backfill from the previously-derived supplier part (supplier + item)+----------------------------------------------------------------------------+UPDATE "purchaseOrderLine" pol+SET "supplierPartId" = sp."supplierPartId"+FROM "purchaseOrder" po+JOIN "supplierPart" sp+ ON sp."supplierId" = po."supplierId"+WHERE pol."purchaseOrderId" = po."id"+ AND pol."itemId" IS NOT NULL+ AND sp."itemId" = pol."itemId";++----------------------------------------------------------------------------+-- 3. Rebuild the view to expose BOTH the stored and the derived value.+-- `pl.*` now emits `supplierPartId` (the line-level stored value). The+-- catalog-derived value is kept under a distinct alias+-- `supplierPartIdFromSupplier` (so there is no duplicate column). Readers+-- pick the line value first, then fall back to the supplier-derived value.+----------------------------------------------------------------------------+DROP VIEW IF EXISTS "purchaseOrderLines";+CREATE OR REPLACE VIEW "purchaseOrderLines" WITH(SECURITY_INVOKER=true) AS (+ SELECT DISTINCT ON (pl.id)+ pl.*,+ sp."supplierPartId" as "supplierPartIdFromSupplier",+ CASE+ WHEN i."thumbnailPath" IS NULL AND mu."thumbnailPath" IS NOT NULL THEN mu."thumbnailPath"+ WHEN i."thumbnailPath" IS NULL AND imu."thumbnailPath" IS NOT NULL THEN imu."thumbnailPath"+ ELSE i."thumbnailPath"+ END as "thumbnailPath",+ i.name as "itemName",+ i."readableIdWithRevision" as "itemReadableId",+ i.description as "itemDescription",+ COALESCE(mu.id, imu.id) as "modelId",+ COALESCE(mu."autodeskUrn", imu."autodeskUrn") as "autodeskUrn",+ COALESCE(mu."modelPath", imu."modelPath") as "modelPath",+ COALESCE(mu."name", imu."name") as "modelName",+ COALESCE(mu."size", imu."size") as "modelSize",+ ic."unitCost" as "unitCost",+ jo."description" as "jobOperationDescription",+ a."name" as "accountName",+ fa."fixedAssetId" as "assetReadableId",+ fa."name" as "assetName"+ FROM "purchaseOrderLine" pl+ INNER JOIN "purchaseOrder" so ON so.id = pl."purchaseOrderId"+ LEFT JOIN "modelUpload" mu ON pl."modelUploadId" = mu."id"+ LEFT JOIN "item" i ON i.id = pl."itemId"+ LEFT JOIN "itemCost" ic ON ic."itemId" = i.id+ LEFT JOIN "modelUpload" imu ON imu.id = i."modelUploadId"+ LEFT JOIN "jobOperation" jo ON jo."id" = pl."jobOperationId"+ LEFT JOIN "account" a ON a.id = pl."accountId"+ LEFT JOIN "fixedAsset" fa ON fa.id = pl."assetId"+ LEFT JOIN "supplierPart" sp ON sp."supplierId" = so."supplierId" AND sp."itemId" = i.id+);diff --git a/packages/documents/src/utils/purchase-order.ts b/packages/documents/src/utils/purchase-order.tsindex 0180e114ac..32e211669f 100644--- a/packages/documents/src/utils/purchase-order.ts+++ b/packages/documents/src/utils/purchase-order.ts@@ -11,7 +11,11 @@ export function getLineDescription(case "Comment":return line?.description;default:- return line?.supplierPartId ?? line?.itemReadableId;+ return (+ line?.supplierPartId ??+ line?.supplierPartIdFromSupplier ??+ line?.itemReadableId+ );}}