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(production): label forecast rows by part, not operation description (#1643)

Brad Barbinae284e13ca35
diff --git a/apps/erp/app/modules/production/production.service.ts b/apps/erp/app/modules/production/production.service.ts
index bab1f450db..e7999732df 100644
--- a/apps/erp/app/modules/production/production.service.ts
+++ b/apps/erp/app/modules/production/production.service.ts
@@ -1115,7 +1115,7 @@ export async function getCapacityReservationsForResources(
.select(
`id, operationId, jobId, resourceKind, resourceId, startAt, endAt, scheduleNote, workHours, isPlaceholder, jobOperationBatchId,
job!inner(jobId, status, dueDate, locationId),
- jobOperation(description, hasConflict, conflictReason),
+ jobOperation(description, hasConflict, conflictReason, jobMakeMethod(item(readableIdWithRevision, name, thumbnailPath, type))),
jobOperationBatch(readableId)`
)
.eq("companyId", companyId)
diff --git a/apps/erp/app/modules/production/ui/Schedule/TimelineDetail.tsx b/apps/erp/app/modules/production/ui/Schedule/TimelineDetail.tsx
index 6aa9adbfaa..8b60c90fcc 100644
--- a/apps/erp/app/modules/production/ui/Schedule/TimelineDetail.tsx
+++ b/apps/erp/app/modules/production/ui/Schedule/TimelineDetail.tsx
@@ -17,7 +17,8 @@ import {
LuX
} from "react-icons/lu";
import { Link } from "react-router";
-import { DateTime } from "~/components";
+import { DateTime, ItemThumbnail } from "~/components";
+import type { ItemType } from "~/modules/shared";
import { path } from "~/utils/path";
import type { TimelineNodeDetail } from "./timeline";
@@ -128,6 +129,10 @@ export function TimelineDetail({
const linkedJobId = detail.jobId ?? jobId;
+ // Show the part's thumbnail in the header when this row carries an item —
+ // a work-center/operator reservation for an operation (a batch has none).
+ const showThumbnail = !!detail.itemReadableId || !!detail.thumbnailPath;
+
// Real (booked) reservations get plant-clock times; approximate/placeholder
// rows stay date-only.
const showTimes =
@@ -228,24 +233,36 @@ export function TimelineDetail({
<div className="flex h-full flex-col border-l border-border bg-card">
{/* Header */}
<div className="flex items-start justify-between gap-3 border-b border-border p-4">
- <div className="flex min-w-0 flex-col gap-1.5">
- <Subheading variant="heavy">{kindLabel[detail.kind]}</Subheading>
- <Heading size="h3" className="truncate">
- {detail.title}
- </Heading>
- <div className="flex items-center gap-2 text-xs text-muted-foreground">
- <span className="inline-flex items-center gap-1.5 font-medium text-foreground">
- <span
- className={cn("size-1.5 rounded-full", STATUS_DOT[status.tone])}
- />
- {status.label}
- </span>
- {relative && (
- <>
- <span className="text-border">·</span>
- <span className="tabular-nums">{relative}</span>
- </>
- )}
+ <div className="flex min-w-0 items-start gap-3">
+ {showThumbnail && (
+ <ItemThumbnail
+ thumbnailPath={detail.thumbnailPath}
+ type={(detail.itemType as ItemType | undefined) ?? undefined}
+ size="lg"
+ />
+ )}
+ <div className="flex min-w-0 flex-col gap-1.5">
+ <Subheading variant="heavy">{kindLabel[detail.kind]}</Subheading>
+ <Heading size="h3" className="truncate">
+ {detail.title}
+ </Heading>
+ <div className="flex items-center gap-2 text-xs text-muted-foreground">
+ <span className="inline-flex items-center gap-1.5 font-medium text-foreground">
+ <span
+ className={cn(
+ "size-1.5 rounded-full",
+ STATUS_DOT[status.tone]
+ )}
+ />
+ {status.label}
+ </span>
+ {relative && (
+ <>
+ <span className="text-border">·</span>
+ <span className="tabular-nums">{relative}</span>
+ </>
+ )}
+ </div>
</div>
</div>
<IconButton
@@ -324,6 +341,17 @@ export function TimelineDetail({
</div>
)}
+ {/* The operation's own description — the part now titles the panel, so
+ keep the work content here for context. */}
+ {detail.operationDescription && (
+ <div className="space-y-1">
+ <Subheading variant="heavy">{t`Operation`}</Subheading>
+ <p className="text-sm text-foreground text-pretty">
+ {detail.operationDescription}
+ </p>
+ </div>
+ )}
+
{isUnscheduled ? (
<p className="text-sm italic text-muted-foreground text-pretty">
<Trans>
@@ -339,6 +367,21 @@ export function TimelineDetail({
{detail.jobReadableId && (
<DetailRow label={t`Job`} value={detail.jobReadableId} />
)}
+ {detail.itemReadableId && (
+ <DetailRow
+ label={t`Part`}
+ value={
+ <span className="flex flex-col items-end">
+ <span>{detail.itemReadableId}</span>
+ {detail.itemName && (
+ <span className="text-xs font-normal text-muted-foreground">
+ {detail.itemName}
+ </span>
+ )}
+ </span>
+ }
+ />
+ )}
{detail.workCenterName && (
<DetailRow label={t`Work Center`} value={detail.workCenterName} />
)}
diff --git a/apps/erp/app/modules/production/ui/Schedule/resourceTimeline.test.ts b/apps/erp/app/modules/production/ui/Schedule/resourceTimeline.test.ts
index dc4f1ae35b..c52029129b 100644
--- a/apps/erp/app/modules/production/ui/Schedule/resourceTimeline.test.ts
+++ b/apps/erp/app/modules/production/ui/Schedule/resourceTimeline.test.ts
@@ -67,6 +67,44 @@ describe("buildResourceTimeline", () => {
expect(child.data.duration).toBe(2 * HOUR);
});
+ it("titles the bar and detail by the part, not the operation description", () => {
+ const result = buildResourceTimeline({
+ reservations: [
+ reservation({
+ operationDescription: "3D Print — ESTIMATED: Inspect camera fit",
+ itemReadableId: "PART-0042",
+ itemName: "Camera Housing",
+ itemThumbnailPath: "_templates/aerospace_satellite/part-0042.svg",
+ itemType: "Part"
+ })
+ ]
+ });
+
+ const bar = result.events.find((e) => e.id === "res-1")!;
+ // The row reads "{job} · {part}" — the description no longer titles it.
+ expect(bar.data.message).toBe("J000001 · PART-0042");
+
+ const detail = result.detailsById["res-1"];
+ expect(detail.title).toBe("J000001 · PART-0042");
+ // The panel carries the part + thumbnail, and keeps the description for context.
+ expect(detail.itemReadableId).toBe("PART-0042");
+ expect(detail.itemName).toBe("Camera Housing");
+ expect(detail.thumbnailPath).toBe(
+ "_templates/aerospace_satellite/part-0042.svg"
+ );
+ expect(detail.operationDescription).toBe(
+ "3D Print — ESTIMATED: Inspect camera fit"
+ );
+ });
+
+ it("falls back to the operation description when the part is unknown", () => {
+ const result = buildResourceTimeline({
+ reservations: [reservation({ operationDescription: "Deburr" })]
+ });
+ const bar = result.events.find((e) => e.id === "res-1")!;
+ expect(bar.data.message).toBe("J000001 · Deburr");
+ });
+
it("interleaves reservations and maintenance by start within a lane", () => {
const result = buildResourceTimeline({
reservations: [
diff --git a/apps/erp/app/modules/production/ui/Schedule/resourceTimeline.ts b/apps/erp/app/modules/production/ui/Schedule/resourceTimeline.ts
index c2fcf0c398..28d58e025d 100644
--- a/apps/erp/app/modules/production/ui/Schedule/resourceTimeline.ts
+++ b/apps/erp/app/modules/production/ui/Schedule/resourceTimeline.ts
@@ -38,6 +38,15 @@ export type ResourceTimelineReservation = {
*/
operationId: string;
operationDescription: string | null;
+ /**
+ * The part this operation produces (its make method's item) — used to title
+ * the bar and the detail panel instead of the operation description, and to
+ * show the item's thumbnail in the panel.
+ */
+ itemReadableId?: string | null;
+ itemName?: string | null;
+ itemThumbnailPath?: string | null;
+ itemType?: string | null;
/**
* Set when this is a Released operation batch's ONE coalesced hold (its
* jobId/operationId are just the anchor member). The bar reads as the
@@ -119,6 +128,27 @@ type Lane = {
const clamp = (value: number, lo: number, hi: number) =>
Math.min(Math.max(value, lo), hi);
+/**
+ * The bar/detail label for a reservation. A batch reads as the batch
+ * ("BAT… · N jobs"); everything else reads as "{job} · {part}" — the operation's
+ * make-method item, NOT its description — falling back to the description only
+ * when the part is unknown, then to the job id alone.
+ */
+function reservationLabel(r: ResourceTimelineReservation): string {
+ if (r.batchReadableId) {
+ return `${r.batchReadableId}${
+ r.batchMemberCount ? ` · ${r.batchMemberCount} jobs` : ""
+ }`;
+ }
+ if (r.itemReadableId) {
+ return `${r.jobReadableId} · ${r.itemReadableId}`;
+ }
+ if (r.operationDescription) {
+ return `${r.jobReadableId} · ${r.operationDescription}`;
+ }
+ return r.jobReadableId;
+}
+
export function buildResourceTimeline(input: {
reservations: ResourceTimelineReservation[];
/**
@@ -356,7 +386,8 @@ export function buildResourceTimeline(input: {
// A reservation → its Gantt bar (+ detail). Reused for operation nodes (the
// machine hold), operator segments, and legacy pool / orphan rows. The detail
- // panel keeps the full "job · operation" label whatever the bar is titled.
+ // panel carries the same "job · part" label as the bar, plus the part's
+ // thumbnail and the operation description for context.
const buildReservationBar = (
r: ResourceTimelineReservation,
parentId: string,
@@ -369,13 +400,7 @@ export function buildResourceTimeline(input: {
const barEnd = clamp(rawEnd, windowStart, windowEnd);
detailsById[r.id] = {
kind: "reservation",
- title: r.batchReadableId
- ? `${r.batchReadableId}${
- r.batchMemberCount ? ` · ${r.batchMemberCount} jobs` : ""
- }`
- : r.operationDescription
- ? `${r.jobReadableId} · ${r.operationDescription}`
- : r.jobReadableId,
+ title: reservationLabel(r),
start: new Date(rawStart).toISOString(),
end: new Date(rawEnd).toISOString(),
durationMs: Math.max(rawEnd - rawStart, 0),
@@ -389,6 +414,11 @@ export function buildResourceTimeline(input: {
workMs: r.workHours ? r.workHours * 3_600_000 : undefined,
jobId: r.jobId,
jobReadableId: r.jobReadableId,
+ operationDescription: r.operationDescription ?? null,
+ itemReadableId: r.itemReadableId ?? null,
+ itemName: r.itemName ?? null,
+ thumbnailPath: r.itemThumbnailPath ?? null,
+ itemType: r.itemType ?? null,
batchId: r.batchId ?? null,
estimatedWorkHours: r.workHours ?? null
};
@@ -422,21 +452,13 @@ export function buildResourceTimeline(input: {
for (const lane of lanes) {
// Operation nodes (the machine hold) with operator segments nested under
// each. The op is the anchor bar; a machine-only or unschedulable op simply
- // has no operators beneath it. Titled "{job} · {op}" so the op reads clearly
- // under its station.
+ // has no operators beneath it. Titled "{job} · {part}" so the op reads
+ // clearly under its station.
const opNodes = [...lane.ops.values()]
.sort((a, b) => byStart(a.machine, b.machine))
.map((op) => {
const node = buildReservationBar(op.machine, lane.id, 2, {
- message: op.machine.batchReadableId
- ? `${op.machine.batchReadableId}${
- op.machine.batchMemberCount
- ? ` · ${op.machine.batchMemberCount} jobs`
- : ""
- }`
- : op.machine.operationDescription
- ? `${op.machine.jobReadableId} · ${op.machine.operationDescription}`
- : op.machine.jobReadableId
+ message: reservationLabel(op.machine)
});
const workerBars = [...op.workers].sort(byStart).map((w) =>
buildReservationBar(w, op.machine.id, 3, {
diff --git a/apps/erp/app/modules/production/ui/Schedule/timeline.ts b/apps/erp/app/modules/production/ui/Schedule/timeline.ts
index 9b4f9369d0..8389a3fa46 100644
--- a/apps/erp/app/modules/production/ui/Schedule/timeline.ts
+++ b/apps/erp/app/modules/production/ui/Schedule/timeline.ts
@@ -43,6 +43,17 @@ export type TimelineNodeDetail = {
*/
jobId?: string;
jobReadableId?: string;
+ /** The operation's own description — shown as a secondary "Operation" row. */
+ operationDescription?: string | null;
+ /**
+ * The part this reservation's operation produces (its make method's item).
+ * `itemReadableId` titles the panel and appears as the "Part" row; the
+ * thumbnail is shown alongside the header.
+ */
+ itemReadableId?: string | null;
+ itemName?: string | null;
+ thumbnailPath?: string | null;
+ itemType?: string | null;
/**
* Set when this reservation is a Released operation batch's coalesced hold.
* The panel opens the batch (not the anchor member's job) when present.
diff --git a/apps/erp/app/routes/api+/mcp+/lib/tool-manifest.digest.json b/apps/erp/app/routes/api+/mcp+/lib/tool-manifest.digest.json
index 0ac8e9e515..5447e11cae 100644
--- a/apps/erp/app/routes/api+/mcp+/lib/tool-manifest.digest.json
+++ b/apps/erp/app/routes/api+/mcp+/lib/tool-manifest.digest.json
@@ -673,7 +673,7 @@
{"name":"production_getBatchableOperations","classification":"READ","paramCount":2,"schema":"4cebb10b56d4","response":"55b8408b15c3","injectAuth":"companyId","permission":"production:view","paginates":false},
{"name":"production_getBatchableProcesses","classification":"READ","paramCount":0,"schema":"efddc7bd8bbc","response":"b0ab8957f96e","injectAuth":"companyId","permission":"production:view","paginates":false},
{"name":"production_getCapacityReservationsByJob","classification":"READ","paramCount":1,"schema":"4999bd4be598","response":"8ea855e0971b","injectAuth":"companyId","permission":"production:view","paginates":false},
- {"name":"production_getCapacityReservationsForResources","classification":"READ","paramCount":2,"schema":"c0f9784197a0","response":"8761b0d72ab9","injectAuth":"companyId","permission":"production:view","paginates":false},
+ {"name":"production_getCapacityReservationsForResources","classification":"READ","paramCount":2,"schema":"c0f9784197a0","response":"fc576887f258","injectAuth":"companyId","permission":"production:view","paginates":false},
{"name":"production_getDemandForecasts","classification":"READ","paramCount":3,"schema":"c24ad31f1eaa","response":"21892ee9e3b8","injectAuth":"companyId","permission":"production:view","paginates":false},
{"name":"production_getDemandProjections","classification":"READ","paramCount":3,"schema":"c24ad31f1eaa","response":"3f9a097c510e","injectAuth":"companyId","permission":"production:view","paginates":false},
{"name":"production_getFailureMode","classification":"READ","paramCount":1,"schema":"4a3e0384d72f","response":"2f49c8d39495","injectAuth":"companyId","permission":"production:view","paginates":false},
diff --git a/apps/erp/app/routes/x+/scheduling+/forecast.tsx b/apps/erp/app/routes/x+/scheduling+/forecast.tsx
index 6fc783c4c8..3f38a9bb0d 100644
--- a/apps/erp/app/routes/x+/scheduling+/forecast.tsx
+++ b/apps/erp/app/routes/x+/scheduling+/forecast.tsx
@@ -433,6 +433,12 @@ export async function loader({ request }: LoaderFunctionArgs) {
jobReadableId: r.job?.jobId ?? r.jobId,
operationId: r.operationId,
operationDescription: r.jobOperation?.description ?? null,
+ itemReadableId:
+ r.jobOperation?.jobMakeMethod?.item?.readableIdWithRevision ?? null,
+ itemName: r.jobOperation?.jobMakeMethod?.item?.name ?? null,
+ itemThumbnailPath:
+ r.jobOperation?.jobMakeMethod?.item?.thumbnailPath ?? null,
+ itemType: r.jobOperation?.jobMakeMethod?.item?.type ?? null,
batchReadableId: r.jobOperationBatch?.readableId ?? null,
batchId: r.jobOperationBatchId ?? null,
batchMemberCount: r.jobOperationBatchId