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): show batch notes to operators

Raul0d8c1d675b0e
diff --git a/apps/erp/app/routes/file+/batch+/$id[.]pdf.tsx b/apps/erp/app/routes/file+/batch+/$id[.]pdf.tsx
index 1730aaeb09..c65f9f7406 100644
--- a/apps/erp/app/routes/file+/batch+/$id[.]pdf.tsx
+++ b/apps/erp/app/routes/file+/batch+/$id[.]pdf.tsx
@@ -29,7 +29,7 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
const batch = await serviceRole
.from("jobOperationBatch")
.select(
- "id, readableId, status, createdAt, process(name), workCenter(name)"
+ "id, readableId, status, notes, createdAt, process(name), workCenter(name)"
)
.eq("id", id)
.eq("companyId", companyId)
@@ -104,6 +104,7 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
}}
processName={batch.data.process?.name ?? null}
workCenterName={workCenterName}
+ notes={batch.data.notes}
members={(members.data ?? [])
.map((m): BatchListMember => {
const thumbnailPath =
diff --git a/apps/mes/app/components/JobOperation/components/BatchOverview.tsx b/apps/mes/app/components/JobOperation/components/BatchOverview.tsx
index c055ae0f90..1e184ad7fc 100644
--- a/apps/mes/app/components/JobOperation/components/BatchOverview.tsx
+++ b/apps/mes/app/components/JobOperation/components/BatchOverview.tsx
@@ -151,23 +151,35 @@ export function BatchOverview({
return next;
});
+ // The planner's notes from the batch builder: plain text, shown first so the
+ // operator reads them before the steps.
+ const notes = batch.notes?.trim() ? batch.notes : null;
+
if (view === "instructions") {
return (
<>
+ {notes && (
+ <Section divider={false} title={t`Batch notes`}>
+ <div className="prose dark:prose-invert whitespace-pre-wrap break-words">
+ {notes}
+ </div>
+ </Section>
+ )}
{workInstructions && (
<Suspense fallback={<TableSkeleton />}>
<Await resolve={workInstructions}>
{(resolved) => (
<>
{resolved.steps.length === 0 &&
- resolved.parameters.length === 0 && (
+ resolved.parameters.length === 0 &&
+ !notes && (
<p className="p-6 text-sm text-muted-foreground">
<Trans>This batch has no work instructions.</Trans>
</p>
)}
{resolved.steps.length > 0 && (
<Section
- divider={false}
+ divider={Boolean(notes)}
title={t`Work instructions`}
description={t`Every job in the batch follows these steps. Record a step for all of them at once.`}
>
diff --git a/packages/documents/src/pdf/BatchListPDF.test.ts b/packages/documents/src/pdf/BatchListPDF.test.ts
new file mode 100644
index 0000000000..32e643c582
--- /dev/null
+++ b/packages/documents/src/pdf/BatchListPDF.test.ts
@@ -0,0 +1,64 @@
+// SPDX-License-Identifier: AGPL-3.0-only
+// 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 { ReactElement, ReactNode } from "react";
+import { Children, isValidElement } from "react";
+import { describe, expect, it } from "vitest";
+import { BatchListPDF, breakLongNotesWord } from "./BatchListPDF";
+import { SAMPLE_JOB_TRAVELER } from "./jobTraveler.samples";
+
+// Every string the batch list prints, read off its element tree.
+function printedText(notes: string | null | undefined): string[] {
+ const document = (BatchListPDF as (p: never) => ReactElement)({
+ company: SAMPLE_JOB_TRAVELER.company,
+ batch: {
+ readableId: "BAT000001",
+ status: "Active",
+ createdAt: "2026-10-01T08:00:00Z"
+ },
+ processName: "Laser Cutting",
+ workCenterName: null,
+ members: [],
+ notes
+ } as never);
+ const texts: string[] = [];
+ const walk = (node: ReactNode) =>
+ Children.forEach(node, (child) => {
+ if (typeof child === "string") texts.push(child);
+ if (!isValidElement(child)) return;
+ walk((child.props as { children?: ReactNode }).children);
+ });
+ walk((document.props as { children?: ReactNode }).children);
+ return texts;
+}
+
+describe("Batch list notes", () => {
+ it("print as typed, line breaks included", () => {
+ const notes = "Cut on the fiber laser.\nDeburr every edge.";
+ const texts = printedText(notes);
+ expect(texts).toContain("Batch Notes");
+ expect(texts).toContain(notes);
+ });
+
+ it("are left out when the batch has none", () => {
+ for (const notes of [null, undefined, "", " \n "]) {
+ expect(printedText(notes)).not.toContain("Batch Notes");
+ }
+ });
+});
+
+describe("breakLongNotesWord", () => {
+ it("keeps a word that fits on a line whole", () => {
+ expect(breakLongNotesWord("Deburr")).toEqual(["Deburr"]);
+ expect(breakLongNotesWord("x".repeat(40))).toEqual(["x".repeat(40)]);
+ });
+
+ it("lets a longer word break every 40 characters", () => {
+ const url = `https://example.com/${"a".repeat(80)}`;
+ const parts = breakLongNotesWord(url);
+ expect(parts.join("")).toBe(url);
+ expect(parts.every((part) => part.length <= 40)).toBe(true);
+ expect(parts).toHaveLength(3);
+ });
+});
diff --git a/packages/documents/src/pdf/BatchListPDF.tsx b/packages/documents/src/pdf/BatchListPDF.tsx
index 9b8dd0f8b5..825a396cf4 100644
--- a/packages/documents/src/pdf/BatchListPDF.tsx
+++ b/packages/documents/src/pdf/BatchListPDF.tsx
@@ -4,6 +4,7 @@
import { formatDate } from "@carbon/utils";
import { Image, Text, View } from "@react-pdf/renderer";
+import { DEFAULT_THEME } from "../template";
import type { Company } from "../types";
import { tw } from "./blocks/jobTraveler/tw";
import { Header, Template } from "./components";
@@ -17,6 +18,26 @@ const COL_ITEM = "w-2/12 text-left pr-4";
const COL_DESCRIPTION = "w-5/12 text-left pr-4";
const COL_QUANTITY = "w-2/12 text-right";
+// The traveler's Job Notes look (components/Note.tsx): a ruled uppercase
+// title over 9pt body text, in the default document theme's colors.
+const NOTES_TITLE = `flex flex-row items-center mt-[20px] mb-[10px] py-[6px] px-[3px] border-t border-b border-[#CCCCCC] text-[9px] font-bold uppercase text-[${DEFAULT_THEME.heading}]`;
+const NOTES_BODY = `text-[9px] text-[${DEFAULT_THEME.text}]`;
+
+// react-pdf breaks a line only between words or at the English hyphenation
+// points it finds, so an unbroken string wider than the page (a URL, a file
+// path) printed past the margin. Notes break at spaces, and a longer word
+// every NOTES_WORD_CHUNK characters.
+const NOTES_WORD_CHUNK = 40;
+
+export function breakLongNotesWord(word: string): string[] {
+ if (word.length <= NOTES_WORD_CHUNK) return [word];
+ const parts: string[] = [];
+ for (let start = 0; start < word.length; start += NOTES_WORD_CHUNK) {
+ parts.push(word.slice(start, start + NOTES_WORD_CHUNK));
+ }
+ return parts;
+}
+
export interface BatchListMember {
id: string;
jobReadableId: string | null;
@@ -39,6 +60,8 @@ interface BatchListPDFProps {
processName: string | null;
workCenterName: string | null;
members: BatchListMember[];
+ // The planner's plain-text notes from the batch builder.
+ notes?: string | null;
locale?: string;
}
@@ -54,6 +77,7 @@ export const BatchListPDF = ({
processName,
workCenterName,
members,
+ notes,
locale
}: BatchListPDFProps) => {
const totalQuantity = members.reduce((sum, m) => sum + (m.quantity ?? 0), 0);
@@ -177,6 +201,19 @@ export const BatchListPDF = ({
<Text style={tw(COL_QUANTITY)}>{totalQuantity}</Text>
</View>
</View>
+
+ {/* Placed like the traveler's Job Notes, after the table. Plain text,
+ so its line breaks print as typed. */}
+ {notes?.trim() ? (
+ <View style={tw("mb-6")}>
+ <View style={tw(NOTES_TITLE)} minPresenceAhead={30}>
+ <Text>Batch Notes</Text>
+ </View>
+ <Text style={tw(NOTES_BODY)} hyphenationCallback={breakLongNotesWord}>
+ {notes}
+ </Text>
+ </View>
+ ) : null}
</Template>
);
};
diff --git a/packages/locale/locales/de/mes.po b/packages/locale/locales/de/mes.po
index 7076762efa..118c2d17fa 100644
--- a/packages/locale/locales/de/mes.po
+++ b/packages/locale/locales/de/mes.po
@@ -287,6 +287,9 @@ msgstr "Los-Details"
msgid "Batch is not available"
msgstr "Charge ist nicht verfügbar"
+msgid "Batch notes"
+msgstr "Los-Notizen"
+
#. placeholder {0}: index + 1
msgid "Batch Number {0}"
msgstr "Chargennummer {0}"
diff --git a/packages/locale/locales/en/mes.po b/packages/locale/locales/en/mes.po
index d439670c66..4d9c5115a3 100644
--- a/packages/locale/locales/en/mes.po
+++ b/packages/locale/locales/en/mes.po
@@ -287,6 +287,9 @@ msgstr "Batch Details"
msgid "Batch is not available"
msgstr "Batch is not available"
+msgid "Batch notes"
+msgstr "Batch notes"
+
#. placeholder {0}: index + 1
msgid "Batch Number {0}"
msgstr "Batch Number {0}"
diff --git a/packages/locale/locales/es/mes.po b/packages/locale/locales/es/mes.po
index 8ea773c95c..195a1109e0 100644
--- a/packages/locale/locales/es/mes.po
+++ b/packages/locale/locales/es/mes.po
@@ -287,6 +287,9 @@ msgstr "Detalles del lote de producción"
msgid "Batch is not available"
msgstr "El lote no está disponible"
+msgid "Batch notes"
+msgstr "Notas del lote de producción"
+
#. placeholder {0}: index + 1
msgid "Batch Number {0}"
msgstr "Número de lote {0}"
diff --git a/packages/locale/locales/fr/mes.po b/packages/locale/locales/fr/mes.po
index 4ac4df80f4..4215d46e8b 100644
--- a/packages/locale/locales/fr/mes.po
+++ b/packages/locale/locales/fr/mes.po
@@ -287,6 +287,9 @@ msgstr "Détails du lot de production"
msgid "Batch is not available"
msgstr "Le lot n'est pas disponible"
+msgid "Batch notes"
+msgstr "Notes du lot de production"
+
#. placeholder {0}: index + 1
msgid "Batch Number {0}"
msgstr "Numéro de lot {0}"
diff --git a/packages/locale/locales/hi/mes.po b/packages/locale/locales/hi/mes.po
index 3860d69d63..599cc10589 100644
--- a/packages/locale/locales/hi/mes.po
+++ b/packages/locale/locales/hi/mes.po
@@ -287,6 +287,9 @@ msgstr "बैच विवरण"
msgid "Batch is not available"
msgstr "बैच उपलब्ध नहीं है"
+msgid "Batch notes"
+msgstr "बैच नोट्स"
+
#. placeholder {0}: index + 1
msgid "Batch Number {0}"
msgstr "बैच नंबर {0}"
diff --git a/packages/locale/locales/it/mes.po b/packages/locale/locales/it/mes.po
index 635a065b6a..b9a460fb03 100644
--- a/packages/locale/locales/it/mes.po
+++ b/packages/locale/locales/it/mes.po
@@ -287,6 +287,9 @@ msgstr "Dettagli del lotto di produzione"
msgid "Batch is not available"
msgstr "Lotto non disponibile"
+msgid "Batch notes"
+msgstr "Note del lotto di produzione"
+
#. placeholder {0}: index + 1
msgid "Batch Number {0}"
msgstr "Numero Lotto {0}"
diff --git a/packages/locale/locales/ja/mes.po b/packages/locale/locales/ja/mes.po
index 5b5f92a271..1075aebd16 100644
--- a/packages/locale/locales/ja/mes.po
+++ b/packages/locale/locales/ja/mes.po
@@ -287,6 +287,9 @@ msgstr "バッチ詳細"
msgid "Batch is not available"
msgstr "バッチは利用可能ではありません"
+msgid "Batch notes"
+msgstr "バッチメモ"
+
#. placeholder {0}: index + 1
msgid "Batch Number {0}"
msgstr "バッチ番号 {0}"
diff --git a/packages/locale/locales/ko/mes.po b/packages/locale/locales/ko/mes.po
index c9c1390477..4448a40097 100644
--- a/packages/locale/locales/ko/mes.po
+++ b/packages/locale/locales/ko/mes.po
@@ -287,6 +287,9 @@ msgstr "배치 상세정보"
msgid "Batch is not available"
msgstr "배치는 가용하지 않습니다"
+msgid "Batch notes"
+msgstr "배치 메모"
+
#. placeholder {0}: index + 1
msgid "Batch Number {0}"
msgstr "배치 번호 {0}"
diff --git a/packages/locale/locales/pl/mes.po b/packages/locale/locales/pl/mes.po
index 504a601db7..ecef12b7cf 100644
--- a/packages/locale/locales/pl/mes.po
+++ b/packages/locale/locales/pl/mes.po
@@ -287,6 +287,9 @@ msgstr "Szczegóły partii produkcyjnej"
msgid "Batch is not available"
msgstr "Partia jest niedostępna"
+msgid "Batch notes"
+msgstr "Notatki partii produkcyjnej"
+
#. placeholder {0}: index + 1
msgid "Batch Number {0}"
msgstr "Numer partii {0}"
diff --git a/packages/locale/locales/pt/mes.po b/packages/locale/locales/pt/mes.po
index 353e8f9104..feb14a8004 100644
--- a/packages/locale/locales/pt/mes.po
+++ b/packages/locale/locales/pt/mes.po
@@ -287,6 +287,9 @@ msgstr "Detalhes do lote de produção"
msgid "Batch is not available"
msgstr "Lote não disponível"
+msgid "Batch notes"
+msgstr "Observações do lote de produção"
+
#. placeholder {0}: index + 1
msgid "Batch Number {0}"
msgstr "Número do Lote {0}"
diff --git a/packages/locale/locales/ru/mes.po b/packages/locale/locales/ru/mes.po
index 669bfa7310..9c642fa790 100644
--- a/packages/locale/locales/ru/mes.po
+++ b/packages/locale/locales/ru/mes.po
@@ -287,6 +287,9 @@ msgstr "Детали серии"
msgid "Batch is not available"
msgstr "Партия недоступна"
+msgid "Batch notes"
+msgstr "Примечания к серии"
+
#. placeholder {0}: index + 1
msgid "Batch Number {0}"
msgstr "Номер партии {0}"
diff --git a/packages/locale/locales/tr/mes.po b/packages/locale/locales/tr/mes.po
index 8aba09424d..3445e8d6eb 100644
--- a/packages/locale/locales/tr/mes.po
+++ b/packages/locale/locales/tr/mes.po
@@ -287,6 +287,9 @@ msgstr "Parti Detayları"
msgid "Batch is not available"
msgstr "Parti kullanılabilir değil"
+msgid "Batch notes"
+msgstr "Parti Notları"
+
#. placeholder {0}: index + 1
msgid "Batch Number {0}"
msgstr "Lot Numarası {0}"
diff --git a/packages/locale/locales/zh/mes.po b/packages/locale/locales/zh/mes.po
index 8f4c7b0bf0..38fd77d414 100644
--- a/packages/locale/locales/zh/mes.po
+++ b/packages/locale/locales/zh/mes.po
@@ -287,6 +287,9 @@ msgstr "生产批次详情"
msgid "Batch is not available"
msgstr "批次不可用"
+msgid "Batch notes"
+msgstr "生产批次备注"
+
#. placeholder {0}: index + 1
msgid "Batch Number {0}"
msgstr "批次号 {0}"