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(items): make Unit of Measure editable on consumables and tools (#1704)

Brad Barbin1705552f8661
diff --git a/apps/erp/app/modules/items/ui/Consumables/ConsumableProperties.tsx b/apps/erp/app/modules/items/ui/Consumables/ConsumableProperties.tsx
index 72deb35856..a863ee40d3 100644
--- a/apps/erp/app/modules/items/ui/Consumables/ConsumableProperties.tsx
+++ b/apps/erp/app/modules/items/ui/Consumables/ConsumableProperties.tsx
@@ -18,8 +18,12 @@ import { Await, Link, useFetcher, useParams } from "react-router";
import { z } from "zod";
import { zfd } from "zod-form-data";
import { MethodBadge, MethodIcon, TrackingTypeIcon } from "~/components";
-import { Enumerable } from "~/components/Enumerable";
-import { Boolean, ItemPostingGroup, Tags } from "~/components/Form";
+import {
+ Boolean,
+ ItemPostingGroup,
+ Tags,
+ UnitOfMeasure
+} from "~/components/Form";
import CustomFormInlineFields from "~/components/Form/CustomFormInlineFields";
import { ItemThumbnailUpload } from "~/components/ItemThumnailUpload";
import { useCompanySettings, useRouteData } from "~/hooks";
@@ -133,7 +137,8 @@ const ConsumableProperties = ({ data }: ConsumablePropertiesProps) => {
| "itemPostingGroupId"
| "consumableId"
| "active"
- | "mpn",
+ | "mpn"
+ | "unitOfMeasureCode",
value: string | null
) => {
const formData = new FormData();
@@ -409,14 +414,27 @@ const ConsumableProperties = ({ data }: ConsumablePropertiesProps) => {
/>
</ValidatedForm>
- <VStack spacing={2}>
- <h3 className="text-xs text-muted-foreground">
- <Trans>Unit of Measure</Trans>
- </h3>
- <Enumerable
- value={routeData?.consumableSummary?.unitOfMeasure ?? null}
+ <ValidatedForm
+ defaultValues={{
+ unitOfMeasureCode:
+ routeData?.consumableSummary?.unitOfMeasureCode ?? undefined
+ }}
+ validator={z.object({
+ unitOfMeasureCode: z
+ .string()
+ .min(1, { message: "Unit of Measure is required" })
+ })}
+ className="w-full"
+ >
+ <UnitOfMeasure
+ label={t`Unit of Measure`}
+ name="unitOfMeasureCode"
+ inline
+ onChange={(value) => {
+ onUpdate("unitOfMeasureCode", value?.value ?? null);
+ }}
/>
- </VStack>
+ </ValidatedForm>
<ItemDescription
value={routeData?.consumableSummary?.description ?? ""}
diff --git a/apps/erp/app/modules/items/ui/Tools/ToolProperties.tsx b/apps/erp/app/modules/items/ui/Tools/ToolProperties.tsx
index 7e824a2b97..1b58390671 100644
--- a/apps/erp/app/modules/items/ui/Tools/ToolProperties.tsx
+++ b/apps/erp/app/modules/items/ui/Tools/ToolProperties.tsx
@@ -24,7 +24,12 @@ import {
MethodIcon,
TrackingTypeIcon
} from "~/components";
-import { Boolean, ItemPostingGroup, Tags } from "~/components/Form";
+import {
+ Boolean,
+ ItemPostingGroup,
+ Tags,
+ UnitOfMeasure
+} from "~/components/Form";
import CustomFormInlineFields from "~/components/Form/CustomFormInlineFields";
import { ReplenishmentSystemIcon } from "~/components/Icons";
import { ItemThumbnailUpload } from "~/components/ItemThumnailUpload";
@@ -139,7 +144,8 @@ const ToolProperties = ({ data }: ToolPropertiesProps) => {
| "itemPostingGroupId"
| "toolId"
| "active"
- | "mpn",
+ | "mpn"
+ | "unitOfMeasureCode",
value: string | null
) => {
const formData = new FormData();
@@ -511,16 +517,27 @@ const ToolProperties = ({ data }: ToolPropertiesProps) => {
onChange={(value) => onUpdate("sourcingType", value)}
/>
- <VStack spacing={2}>
- <h3 className="text-xs text-muted-foreground">
- <Trans>Unit of Measure</Trans>
- </h3>
- {routeData?.toolSummary?.unitOfMeasure && (
- <Badge variant="secondary">
- {routeData.toolSummary.unitOfMeasure}
- </Badge>
- )}
- </VStack>
+ <ValidatedForm
+ defaultValues={{
+ unitOfMeasureCode:
+ routeData?.toolSummary?.unitOfMeasureCode ?? undefined
+ }}
+ validator={z.object({
+ unitOfMeasureCode: z
+ .string()
+ .min(1, { message: "Unit of Measure is required" })
+ })}
+ className="w-full"
+ >
+ <UnitOfMeasure
+ label={t`Unit of Measure`}
+ name="unitOfMeasureCode"
+ inline
+ onChange={(value) => {
+ onUpdate("unitOfMeasureCode", value?.value ?? null);
+ }}
+ />
+ </ValidatedForm>
<ItemDescription
value={routeData?.toolSummary?.description ?? ""}
diff --git a/apps/mes/app/components/JobOperation/components/BatchCompleteModal.tsx b/apps/mes/app/components/JobOperation/components/BatchCompleteModal.tsx
index af0df0123c..8565e63ce7 100644
--- a/apps/mes/app/components/JobOperation/components/BatchCompleteModal.tsx
+++ b/apps/mes/app/components/JobOperation/components/BatchCompleteModal.tsx
@@ -27,7 +27,16 @@ import { path } from "~/utils/path";
const cellInputClass =
"block h-full min-h-12 w-full bg-transparent px-3 text-right font-mono text-base tabular-nums outline-none transition-colors focus:ring-2 focus:ring-inset focus:ring-ring disabled:cursor-not-allowed disabled:opacity-40";
-const digitsOnly = (value: string) => value.replace(/[^0-9]/g, "");
+// Allow a decimal quantity — a job's operation quantity can be fractional (any
+// non-discrete unit of measure). Keep digits and a single leading decimal point;
+// strip everything else and any extra dots.
+const numericOnly = (value: string) => {
+ const cleaned = value.replace(/[^0-9.]/g, "");
+ const dot = cleaned.indexOf(".");
+ return dot === -1
+ ? cleaned
+ : cleaned.slice(0, dot + 1) + cleaned.slice(dot + 1).replace(/\./g, "");
+};
const toNumber = (value: string) => Number(value) || 0;
// The batch completion form, opened from the batched operation view. Posts to
@@ -80,7 +89,7 @@ export function BatchCompleteModal({
);
const setRow = (i: number, key: "quantity" | "scrapQuantity", v: string) =>
setRows((prev) =>
- prev.map((r, idx) => (idx === i ? { ...r, [key]: digitsOnly(v) } : r))
+ prev.map((r, idx) => (idx === i ? { ...r, [key]: numericOnly(v) } : r))
);
const isExcludedRow = (i: number) =>
@@ -229,7 +238,7 @@ export function BatchCompleteModal({
>
<input
type="text"
- inputMode="numeric"
+ inputMode="decimal"
name={`members[${i}].quantity`}
aria-label={t`Quantity`}
value={rows[i]?.quantity ?? ""}
@@ -249,7 +258,7 @@ export function BatchCompleteModal({
>
<input
type="text"
- inputMode="numeric"
+ inputMode="decimal"
name={`members[${i}].scrapQuantity`}
aria-label={t`Scrap`}
value={rows[i]?.scrapQuantity ?? ""}
diff --git a/apps/mes/app/services/models.ts b/apps/mes/app/services/models.ts
index 23dc8c7799..31c087669b 100644
--- a/apps/mes/app/services/models.ts
+++ b/apps/mes/app/services/models.ts
@@ -256,8 +256,13 @@ export const completeJobOperationBatchValidator = z.object({
// disabled and therefore omitted from FormData. The route forces
// excluded members to 0 after validation and coerces an omitted
// included quantity to 0, so `undefined` never reaches the edge fn.
- quantity: zfd.numeric(z.number().int().min(0).optional()),
- scrapQuantity: zfd.numeric(z.number().int().min(0).optional()),
+ // Not integer-only: a job's operation quantity can be fractional (any
+ // non-discrete unit of measure), so the pre-filled remainder — and the
+ // operator's edit — must accept decimals, matching single-op completion
+ // (baseQuantityValidator). An `.int()` here silently failed validation
+ // and the modal never submitted.
+ quantity: zfd.numeric(z.number().min(0).optional()),
+ scrapQuantity: zfd.numeric(z.number().min(0).optional()),
// Batch-tracked output: the member's WIP entity finalized as the
// produced lot. Its lot number was planned at batch creation and is
// resolved server-side — never an operator input.