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
Plan: Picking Lists Honor Item Supersession (#1210)
- Date: 2026-07-30
- Branch:
fix/picking-supersession-1210→ PR basemain - Issue: https://github.com/crbnos/carbon/issues/1210
Problem
Picking ignores itemSupersession entirely:
- Superseded predecessors surface for picking —
get_picking_schedulecountsStock Only(spares-only) andNo Stock(obsolete) materials as production pick demand. - Successors are never considered — when a job material references a superseded item that
is out of stock, generation/availability never redirect to the effective successor
(
successorItemId, effectivity date, conversion factor), so jobs show false shortages.
Grounded current state
itemSupersession(itemId PK, companyId, supersessionMode, successorItemId, discontinuationDate, successorEffectivityDate, conversionFactor DEFAULT 1).minimumReserveQuantitylives onitemPlanning(per item+location). Modes:Consume First,Prefer New,Stock Only,No Stock.- Precedent —
get_purchasing_planning/get_production_planning(20260618171234) excludeNo Stock+ past-discontinuation phase-out items and floorStock Onlyto the reserve. - Precedent — shared
buildSupersessionRedirectMap(functions/lib/supersession-pick.ts) used by MRP + job creation; onlyConsume First/Prefer Newredirect there (Stock Only is reserve-governed for planning). Picking differs — see D2. get_picking_schedule(20260720160557): per-operation aggregate; thepicksCTE readsjobMaterialwherequantityToIssue > 0. The materialitemIdis used only in the staged-lineside check (not surfaced). OutputitemIdis the make-method's parent assembly.generatePickingList(inventory.service.ts~L3151): copiesjobMaterial.itemIdverbatim onto eachpickingListLine. The substitution injection point.get_picking_list_availability(20260614183507): per line, warehouse on-hand ofpll.itemId.pickingListLine.jobMaterialIdFK already links back to the source material → a substitution is derivable asline.itemId != jobMaterial.itemId. No new column needed.
Design decisions
- D1 — No schema/type changes. RPCs keep their exact
RETURNS TABLE(filter rows only); substitution reuses existing columns anditemSupersessionis already in the generated types, so no generated type is expected to change. Even so, per repo convention runpnpm run generate:typesafter any migration change, before typechecking (regenerate in CI or an approved DB environment when local Postgres is unavailable) rather than relying on the committed generated types. - D2 — Picking-specific redirect semantics (differs from MRP's map):
Mode Pick behavior Consume FirstPick predecessor; only when predecessor has zero warehouse on-hand AND an effective successor with stock exists → substitute the line to the successor. (Conservative: never leaves predecessor stock unused, satisfies "predecessor out of stock → pick successor".) Prefer NewEffective successor → pick successor; else predecessor (fallback until effective). Stock OnlyEffective successor → pick successor (no production use of the reserved predecessor); else skip (nothing valid to pick). No StockSkip (obsolete, no successor). - "Effective successor" =
successorItemIdset AND (successorEffectivityDateIS NULL OR<= today). - Conversion: successor
quantityToPick = quantityToIssue * conversionFactor.
- "Effective successor" =
- D3 — No line splitting. One
pickingListLineperjobMaterialpreserved (downstream consumption assumes it). Consume First substitutes the whole line only when the predecessor is fully out — avoids a 2-line split whose FK/consumption impact can't be verified without a DB. - D4 — Discontinuation date does NOT suppress picks. Planning suppresses new orders past
discontinuation; picking fulfills existing job demand. A job that already needs the part must
still be pickable. Only supersession mode + successor effectivity gate picking.
- Effective-date rule (one basis for both layers). Successor effectivity is evaluated against
the UTC calendar date everywhere: the SQL uses
(now() AT TIME ZONE 'UTC')::dateandgeneratePickingListusestoday("UTC"). This removes any DB-session / server-process timezone skew, so generation and the schedule/availability RPCs always resolve the same effective successor (no boundary case where availability checks the predecessor while generation writes the successor).
- Effective-date rule (one basis for both layers). Successor effectivity is evaluated against
the UTC calendar date everywhere: the SQL uses
- D5 — Availability RPC reports the line's OWN pick item warehouse on-hand. Because generation
already redirects a substituted line's
itemIdto the effective successor (D2/D3),availableQuantityreflects exactly what the line consumes — no successor fold-in. Folding a successor's stock into a line still targeting the predecessor is deliberately avoided: with no line-splitting (D3) that line consumes the predecessor, so a fold-in would mask a real predecessor shortage and could double-count a successor that also has its own line on the list. Shape unchanged. - D6 — UI marker (polish):
getPickingListLinesalso selectsjobMaterial(itemId); the line table shows a "↩ from <predecessor>" marker whenline.itemId != jobMaterial.itemId.
Tasks
- Migration
packages/database/supabase/migrations/{ts}_picking-supersession.sql:CREATE OR REPLACE FUNCTION get_picking_schedule(...)— same signature/return; in thepicksCTE add a LEFT JOIN LATERAL resolving each material'spickItemId(D2, single-hop), exclude rows wherepickItemId IS NULL, and key the staged-lineside check onpickItemId.CREATE OR REPLACE FUNCTION get_picking_list_availability(...)— same signature/return; the line's own pick-item warehouse on-hand, no successor fold-in (D5).- Verify: no precision on
NUMERIC;SECURITY INVOKER; identicalRETURNS TABLE.
generatePickingList(inventory.service.ts): fetchitemSupersessionfor the materials' items; a pureresolvePickTarget(...)helper (D2) chooses{ itemId, factor }or skip; compute on-hand/source for the resolved item; writeitemId= resolved,quantityToPick= converted.getPickingListLines: addjobMaterial(itemId)to the select (D6).- UI
PickingListLines.tsx: render the substituted-from marker (D6). - Test (
inventoryvitest): unit-testresolvePickTargetacross all four modes + effectivity + conversion + out-of-stock branch (red→green). - Verify:
pnpm run generate:types(after the migration, before typecheck — run in CI/an approved DB env if local Postgres is unavailable);pnpm exec turbo run typecheck --filter=erp --filter=@carbon/database;pnpm run lint; the new unit test. (No local DB → RPC bodies verified by SQL review, not applied.)
Out of scope / risks
- Multi-hop supersession chains in SQL are single-hop only (matches planning-function style); the TS resolver can collapse if needed but MRP/job-creation already redirect at creation, so a chained predecessor reaching picking is an edge case.
- No browser/DB verification here (env has no Postgres). Migration correctness is by review; the PR is
agent:needs-verificationfor a human to apply + smoke-test.