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.
TypeScript ai-agentsbill-of-materialserpinventory-managementleanmanufacturingmanufacturing-execution-systemmcp-servermesmrpopen-source-erppostgresqlproduction-planningqmsquality-management-systemreact-routerself-hostedsupabasetraceabilitytypescript
fix(mes): exclude expired lots from the FEFO issue suggestion
Sidwebworkse9cc86aadc4d
diff --git a/apps/erp/app/routes/api+/mcp+/lib/tool-metadata.json b/apps/erp/app/routes/api+/mcp+/lib/tool-metadata.jsonindex 09edb63537..2409c58eac 100644--- a/apps/erp/app/routes/api+/mcp+/lib/tool-metadata.json+++ b/apps/erp/app/routes/api+/mcp+/lib/tool-metadata.json@@ -1,5 +1,5 @@{- "generated": "2026-07-30T14:40:04.298Z",+ "generated": "2026-07-30T16:43:25.338Z","totalTools": 1401,"modules": 15,"tools": [diff --git a/apps/mes/app/services/inventory.service.ts b/apps/mes/app/services/inventory.service.tsindex 1ccbe4f2ae..a474b03b6c 100644--- a/apps/mes/app/services/inventory.service.ts+++ b/apps/mes/app/services/inventory.service.ts@@ -318,10 +318,20 @@ export async function getSuggestedAllocationForMaterial(});if (error || !data) return [];+ // Never suggest an expired lot. FEFO puts the earliest expiry FIRST, so with+ // expired stock on hand the greedy fill would suggest exactly the lots the+ // issue modal refuses to offer (expiredEntityPolicy 'Block' drops them from+ // the options), netting the seed to nothing. An expired lot is never the+ // "correct batch to use" — skip them regardless of policy.+ const today = new Date().toISOString().slice(0, 10);+ const unexpired = data.filter(+ (row) => !row.expirationDate || row.expirationDate >= today+ );+// Sort in the app: the RPC's internal ORDER BY is not guaranteed through// PostgREST (SQL-function inlining), so ordering is authoritative here.const ordered = sortLotsByPickMethod(- data.map((row) => ({+ unexpired.map((row) => ({trackedEntityId: row.trackedEntityId,readableId: row.readableId,availableQuantity: Number(row.availableQuantity ?? 0),