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(sales): don't require method type when selling a Fixed Asset (#1155)

Brad Barbin5a1e6a2cc1fd
diff --git a/apps/erp/app/modules/invoicing/invoicing.models.ts b/apps/erp/app/modules/invoicing/invoicing.models.ts
index c17dbcc1aa..051d97931d 100644
--- a/apps/erp/app/modules/invoicing/invoicing.models.ts
+++ b/apps/erp/app/modules/invoicing/invoicing.models.ts
@@ -233,13 +233,19 @@ export const salesInvoiceLineValidator = z
message: "Type is required"
})
}),
- methodType: z
- .enum(methodType, {
- errorMap: (issue, ctx) => ({
- message: "Method is required"
+ // Wrapped in zfd.text so an empty-string submission (the form always posts a
+ // hidden methodType) coerces to undefined instead of failing the enum check.
+ // Requiredness is enforced conditionally by the refine below, which exempts
+ // Fixed Asset lines.
+ methodType: zfd.text(
+ z
+ .enum(methodType, {
+ errorMap: (issue, ctx) => ({
+ message: "Method is required"
+ })
})
- })
- .optional(),
+ .optional()
+ ),
purchaseOrderId: zfd.text(z.string().optional()),
purchaseOrderLineId: zfd.text(z.string().optional()),
itemId: zfd.text(z.string().optional()),
diff --git a/apps/erp/app/modules/sales/sales.models.ts b/apps/erp/app/modules/sales/sales.models.ts
index 1bbdb3652a..bf80873849 100644
--- a/apps/erp/app/modules/sales/sales.models.ts
+++ b/apps/erp/app/modules/sales/sales.models.ts
@@ -753,11 +753,17 @@ export const salesOrderLineValidator = z
description: zfd.text(z.string().optional()),
itemId: zfd.text(z.string().optional()),
locationId: z.string().min(0, { message: "Location is required" }),
- methodType: z
- .enum(methodType, {
- errorMap: () => ({ message: "Method is required" })
- })
- .optional(),
+ // Wrapped in zfd.text so an empty-string submission (the form always posts a
+ // hidden methodType) coerces to undefined instead of failing the enum check.
+ // Requiredness is enforced conditionally by the refine below, which exempts
+ // Comment and Fixed Asset lines.
+ methodType: zfd.text(
+ z
+ .enum(methodType, {
+ errorMap: () => ({ message: "Method is required" })
+ })
+ .optional()
+ ),
modelUploadId: zfd.text(z.string().optional()),
promisedDate: zfd.text(z.string().optional()),
saleQuantity: zfd.numeric(z.number().optional()),