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 storage rule message {condition.name} showing UUID for storage unit (#861)

Sida43442b8eef4
diff --git a/apps/erp/app/modules/storageRules/ui/useValueOptions.ts b/apps/erp/app/modules/storageRules/ui/useValueOptions.ts
index c0a8c05b38..3296031190 100644
--- a/apps/erp/app/modules/storageRules/ui/useValueOptions.ts
+++ b/apps/erp/app/modules/storageRules/ui/useValueOptions.ts
@@ -10,7 +10,13 @@ import {
} from "~/modules/items/items.models";
export type ValueOption = { value: string; label: string };
-export type ValueOptionsByLoader = Record<ValueOptionsLoader, ValueOption[]>;
+// Partial: not every loader has a flat option list in the builder UI. The
+// `storageUnits` loader exists only for the server-side message resolver
+// ({condition[n].name} → bin name); the builder uses the hierarchical
+// StorageUnitValuePicker for that field, so no flat options are supplied here.
+export type ValueOptionsByLoader = Partial<
+ Record<ValueOptionsLoader, ValueOption[]>
+>;
const enumOptions = (arr: readonly string[]): ValueOption[] =>
arr.map((v) => ({ value: v, label: v }));
diff --git a/packages/ee/src/storageRules/server.ts b/packages/ee/src/storageRules/server.ts
index 99ad602913..00f6afa5e7 100644
--- a/packages/ee/src/storageRules/server.ts
+++ b/packages/ee/src/storageRules/server.ts
@@ -198,6 +198,13 @@ const LOADERS: Record<ValueOptionsLoader, LoaderFn | null> = {
.eq("companyId", id);
return (data ?? []) as { id: string; name: string }[];
},
+ storageUnits: async (c, id) => {
+ const { data } = await c
+ .from("storageUnit")
+ .select("id, name")
+ .eq("companyId", id);
+ return (data ?? []) as { id: string; name: string }[];
+ },
itemPostingGroups: async (c, id) => {
const { data } = await c
.from("itemPostingGroup")
@@ -221,7 +228,8 @@ async function buildConditionValueResolver(
const byLoader = new Map<ValueOptionsLoader, Set<string>>();
for (const cond of conditions) {
const def = getFieldDef(cond.field);
- if (!def?.valueOptionsLoader || def.type !== "id") continue;
+ if (!def?.valueOptionsLoader) continue;
+ if (def.type !== "id" && def.type !== "storageUnit") continue;
if (LOADERS[def.valueOptionsLoader] === null) continue;
if (cond.value == null) continue;
diff --git a/packages/utils/src/field-registry.ts b/packages/utils/src/field-registry.ts
index 46d2f50b9b..e0de8aca74 100644
--- a/packages/utils/src/field-registry.ts
+++ b/packages/utils/src/field-registry.ts
@@ -30,6 +30,7 @@ export type FieldType =
export type ValueOptionsLoader =
| "locations"
| "storageTypes"
+ | "storageUnits"
| "itemTypes"
| "replenishmentSystems"
| "itemTrackingTypes"
@@ -222,13 +223,16 @@ export const FIELD_REGISTRY: FieldDef[] = [
nullable: true,
label: "Storage unit",
// `"storageUnit"` triggers the hierarchical drill-down picker in the
- // rule-builder UI (Location → drilldown). No flat loader needed.
+ // rule-builder UI (Location → drilldown) — no flat options list. The
+ // loader is used only by the evaluator's `{condition[n].name}` resolver
+ // to map the stored bin UUID back to its display name in messages.
type: "storageUnit",
// Drill picker selects a single bin — `in`/`notIn` would require a
// multi-select UI that doesn't exist. Restrict to scalar ops.
operators: SCALAR_OPS,
context: "storage",
- targetType: "item"
+ targetType: "item",
+ valueOptionsLoader: "storageUnits"
}),
fields.synthetic({
path: "storageUnit.storageTypeId",