Skip to content

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.

fix(documents): show item revision on purchase order lines with a supplier part number

naveenkashb172fc6eaf96
diff --git a/packages/documents/src/utils/purchase-order.test.ts b/packages/documents/src/utils/purchase-order.test.ts
index 730db483d4..80c2bdcc33 100644
--- a/packages/documents/src/utils/purchase-order.test.ts
+++ b/packages/documents/src/utils/purchase-order.test.ts
@@ -2,8 +2,64 @@
// Carbon (github.com/crbnos/carbon). Modified or adapted versions of this file,
// including ports, remain AGPLv3; serving them over a network requires releasing their source.
+import type { Database } from "@carbon/database";
import { describe, expect, it } from "vitest";
-import { getPurchaseOrderDisplayId } from "./purchase-order";
+import {
+ getLineDescription,
+ getPurchaseOrderDisplayId
+} from "./purchase-order";
+
+type Line = Database["public"]["Views"]["purchaseOrderLines"]["Row"];
+const line = (overrides: Partial<Line>) =>
+ ({ purchaseOrderLineType: "Part", ...overrides }) as Line;
+
+// `itemReadableId` is the view's `readableIdWithRevision`, so it is the only
+// place the revision reaches the document.
+describe("getLineDescription", () => {
+ it("shows the item id on its own when there is no supplier part number", () => {
+ expect(getLineDescription(line({ itemReadableId: "P000123.B" }))).toBe(
+ "P000123.B"
+ );
+ expect(
+ getLineDescription(
+ line({ itemReadableId: "P000123.B", supplierPartId: "" })
+ )
+ ).toBe("P000123.B");
+ });
+
+ it("keeps the item id and revision next to the supplier part number", () => {
+ expect(
+ getLineDescription(
+ line({ itemReadableId: "P000123.B", supplierPartId: "SUP-778" })
+ )
+ ).toBe("P000123.B (SUP-778)");
+ expect(
+ getLineDescription(
+ line({
+ itemReadableId: "P000123.B",
+ supplierPartId: "",
+ supplierPartIdFromSupplier: "SUP-778"
+ })
+ )
+ ).toBe("P000123.B (SUP-778)");
+ });
+
+ it("does not repeat a supplier part number that equals the item id", () => {
+ expect(
+ getLineDescription(
+ line({ itemReadableId: "P000123.B", supplierPartId: "P000123.B" })
+ )
+ ).toBe("P000123.B");
+ });
+
+ it("falls back to the supplier part number when the line has no item", () => {
+ expect(
+ getLineDescription(
+ line({ itemReadableId: null, supplierPartId: "SUP-778" })
+ )
+ ).toBe("SUP-778");
+ });
+});
// Suffix rules live in revision.test.ts; this pins field mapping only.
describe("getPurchaseOrderDisplayId", () => {
diff --git a/packages/documents/src/utils/purchase-order.ts b/packages/documents/src/utils/purchase-order.ts
index 09d2325d5f..94f08fbb3c 100644
--- a/packages/documents/src/utils/purchase-order.ts
+++ b/packages/documents/src/utils/purchase-order.ts
@@ -15,15 +15,21 @@ export function getLineDescription(
return line?.description;
case "Comment":
return line?.description;
- default:
+ default: {
// Use `||` (not `??`) so an empty-string supplier part number falls
- // through to the item id. Supplier parts with no part number get
- // backfilled onto the line as "", and `??` would render a blank line.
- return (
- line?.supplierPartId ||
- line?.supplierPartIdFromSupplier ||
- line?.itemReadableId
- );
+ // through. Supplier parts with no part number get backfilled onto the
+ // line as "", and `??` would render a blank line.
+ const supplierPartId =
+ line?.supplierPartId || line?.supplierPartIdFromSupplier;
+ // `itemReadableId` is the view's `readableIdWithRevision` — the only
+ // place the revision reaches the document, so the supplier part number
+ // goes beside it rather than in its place (as the sales order does with
+ // the customer part number).
+ if (!line?.itemReadableId) return supplierPartId;
+ return supplierPartId && supplierPartId !== line.itemReadableId
+ ? `${line.itemReadableId} (${supplierPartId})`
+ : line.itemReadableId;
+ }
}
}