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): drop empty option rows on assembly instruction List steps

Raul750ba5695072
diff --git a/apps/erp/app/modules/production/production.models.test.ts b/apps/erp/app/modules/production/production.models.test.ts
new file mode 100644
index 0000000000..cc27064c4b
--- /dev/null
+++ b/apps/erp/app/modules/production/production.models.test.ts
@@ -0,0 +1,54 @@
+// 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 { describe, expect, it } from "vitest";
+import { assemblyInstructionStepValidator } from "./production.models";
+
+// An assembly instruction List step needs at least one option, like the bill of
+// process steps (shared.models.test.ts). Blank rows are dropped first, so the
+// empty row "Add option" leaves behind never blocks a save and is never stored.
+describe("assemblyInstructionStepValidator list options", () => {
+ const listStep = (listValues?: string[]) => ({
+ assemblyInstructionId: "ai1",
+ title: "Pick a finish",
+ type: "List" as const,
+ listValues
+ });
+
+ const listValuesError = (listValues?: string[]) => {
+ const result = assemblyInstructionStepValidator.safeParse(
+ listStep(listValues)
+ );
+ if (result.success) return undefined;
+ return result.error.issues.find(
+ (issue) => issue.path.join(".") === "listValues"
+ )?.message;
+ };
+
+ it("requires at least one option", () => {
+ expect(listValuesError(undefined)).toBe("List options are required");
+ expect(listValuesError([])).toBe("List options are required");
+ });
+
+ it("treats a list of blank rows as no options", () => {
+ expect(listValuesError(["", " "])).toBe("List options are required");
+ });
+
+ it("drops a trailing empty row instead of refusing the save", () => {
+ const result = assemblyInstructionStepValidator.safeParse(
+ listStep(["Matte", "Gloss", ""])
+ );
+ expect(result.success).toBe(true);
+ expect(result.data?.listValues).toEqual(["Matte", "Gloss"]);
+ });
+
+ it("does not require options on other step types", () => {
+ expect(
+ assemblyInstructionStepValidator.safeParse({
+ ...listStep(),
+ type: "Task"
+ }).success
+ ).toBe(true);
+ });
+});
diff --git a/apps/erp/app/modules/production/production.models.ts b/apps/erp/app/modules/production/production.models.ts
index b1dc32f05b..b223ca88b3 100644
--- a/apps/erp/app/modules/production/production.models.ts
+++ b/apps/erp/app/modules/production/production.models.ts
@@ -1564,7 +1564,7 @@ const assemblyInstructionStepFields = z.object({
unitOfMeasureCode: zfd.text(z.string().optional()),
minValue: zfd.numeric(z.number().min(0).optional()),
maxValue: zfd.numeric(z.number().min(0).optional()),
- listValues: z.array(z.string()).optional(),
+ listValues: stepListValues,
componentNodeIds: jsonField(z.array(z.string()).optional()),
motion: jsonField(motionSchema.optional()),
camera: jsonField(cameraSchema.nullable().optional()),
@@ -1585,11 +1585,7 @@ function refineAssemblyInstructionStep(
}
if (
data.type === "List" &&
- !(
- Array.isArray(data.listValues) &&
- data.listValues.length > 0 &&
- data.listValues.every((option) => option.trim() !== "")
- )
+ !(Array.isArray(data.listValues) && data.listValues.length > 0)
) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
diff --git a/apps/erp/app/modules/production/ui/Assemblies/AssemblyInstructionProperties.tsx b/apps/erp/app/modules/production/ui/Assemblies/AssemblyInstructionProperties.tsx
index d11663ede9..e3081868c5 100644
--- a/apps/erp/app/modules/production/ui/Assemblies/AssemblyInstructionProperties.tsx
+++ b/apps/erp/app/modules/production/ui/Assemblies/AssemblyInstructionProperties.tsx
@@ -619,7 +619,7 @@ function StepForm({
</VStack>
)}
{stepType === "List" && (
- <ArrayInput name="listValues" label={t`List Options`} />
+ <ArrayInput name="listValues" label={t`List Options`} isRequired />
)}
<BooleanInput
name="required"