Skip to content

Cold-Chain OMS, WMS & FEFO ​

The cold-chain Order and Warehouse Management subsystem (@latticedx/plugin-dxos-studio) manages order fulfillment, lot-level inventory (latticeStockLots), First-Expired-First-Out (FEFO) allocation constrained by temperature bands, and automated Mean Kinetic Temperature (MKT) quarantine holds. Every stock mutation executes inside a PostgreSQL transaction using row-level SELECT ... FOR UPDATE locks, records latticeDataLineage edges, and appends an Ed25519-signed entry to latticeCryptoLedger.

Data Model and State Machines ​

All cold-chain collections are isolated by organizationId under PostgreSQL 16 FORCE ROW LEVEL SECURITY. Direct REST CRUD mutations against these collections are blocked by wms-direct-guard.js; client portals and external integrations must invoke the dxosWms resource actions.

CollectionPurposePrimary Business KeysValid Lifecycle States
latticeOrdersOperational and fulfillment ordersorganizationId, codedraft, submitted, approved, in_progress, completed, cancelled
latticeOrderLinesSKU and thermal-band line itemsorganizationId, orderCode, lineNopending, partial, allocated, dispatched, delivered
latticeStockLotsInventory lots bound to locations and IIoT assetsorganizationId, lotCode, skuavailable, reserved, depleted, hold_mkt, expired, quarantined
latticeSlaPoliciesPriority-scoped SLA warning and breach thresholdsorganizationId, targetCollection, priorityactive (warnAfterMinutes, breachAfterMinutes)
latticeIncidentCasesOperational or thermal excursion incidentsorganizationId, fingerprint (SHA-256)open, acknowledged, resolved, closed

Any lot whose status belongs to BLOCKED_LOT_STATUSES (hold_mkt, expired, quarantined) is excluded from FEFO allocation and rejected at physical stock issue with HTTP 409 WMS_LOT_ON_HOLD.

Core Fields on Cold-Chain Stock Lots (latticeStockLots)
ParameterTypeDefaultDescription
lotCoderequired
string—Unique lot identifier within the organization.
skurequired
string—Product SKU matched against order lines during FEFO allocation.
assetEntityId
string—NGSI-LD URN of the cold room or refrigerated container, formatted as urn:ngsi-ld:Asset:<orgId>:native:<id>.
qtyOnHandrequired
number—Total physical quantity currently stored in the warehouse.
qtyReserved
number0Quantity reserved for pending or allocated order lines.
expiryDaterequired
datetime—Expiration timestamp used as the primary ascending sort key in FEFO.
targetTempMinC
number—Minimum allowed storage temperature (°C).
targetTempMaxC
number—Maximum allowed storage temperature (°C); used as the default MKT threshold.
mktCelsius
number—Latest computed Arrhenius Mean Kinetic Temperature (°C).

Receiving and Temperature-Band FEFO Allocation ​

Stock intake via dxosWms:receiveStock creates or updates a lot in latticeStockLots with warehouse placement, linked IIoT assetEntityId, and storage temperature limits. When fulfilling an order line, allocateFefo acquires pessimistic row locks (findLockedLots with LOCK.UPDATE) over all available lots matching the requested sku, filters out expired lots or incompatible thermal bands, and sorts candidates in ascending order of (expiryDate, id).

POST/api/dxosWms:allocateFefo
Bearer JWT | ldx_pat_*write, wms
Reserves compatible non-blocked stock lots in FEFO order and writes data lineage edges.
Input Parameters for dxosWms:allocateFefo
ParameterTypeDefaultDescription
skurequired
string—Target SKU to allocate (maximum 128 characters).
quantityrequired
number—Quantity requested for allocation (> 0).
orderCode
string—Order code for line binding; may be paired with orderId.
lineNo
integer1Positive integer order line sequence number.
minTempC
number—Minimum required transport/storage temperature (°C).
maxTempC
number—Maximum required transport/storage temperature (°C).
now
datetime—Reference timestamp for expiry checks (defaults to server time).

Within the same database transaction, the engine increments qtyReserved on each selected lot, creates or updates the latticeOrderLines row to allocated (or partial when shortfall > 0), appends wms.fefo_allocated to latticeCryptoLedger, and writes allocated_to edges into latticeDataLineage.

bash
curl -X POST https://app.example.com/api/dxosWms:allocateFefo \
  -H "Authorization: Bearer ldx_pat_a1b2c3d4_..." \
  -H "Content-Type: application/json" \
  -d '{
    "orderCode": "ORD-2026-0192",
    "lineNo": 1,
    "sku": "VAC-COLD-02",
    "quantity": 120,
    "minTempC": 2,
    "maxTempC": 8
  }'

Stock Issue and Lot Guardrails ​

Physical dispatch via dxosWms:issueStock locks the target lot row (lotId or lotCode) and re-verifies that the lot is not in BLOCKED_LOT_STATUSES and has not expired. The handler deducts qtyOnHand and adjusts qtyReserved; when qtyOnHand reaches 0, the lot transitions to depleted, the linked order line moves to dispatched, and wms.stock_issued is recorded in the PKI ledger.

POST/api/dxosWms:issueStock
Bearer JWT | ldx_pat_*write, wms
Deducts physical stock from a valid lot, validates hold/expiry status, and marks order lines dispatched.
dxosWms EndpointMethodRequired ScopeResponsibility
/api/dxosWms:orderLinesGETread, wmsLists order lines filtered by orderCode or orderId.
/api/dxosWms:saveOrderLinePOSTwrite, wmsCreates or updates SKU, requested quantity, and temperature band on a line.
/api/dxosWms:receiveStockPOSTwrite, wmsReceives a new lot with expiry date, IIoT asset URN, and target thermal band.
/api/dxosWms:lotsGETread, wmsLists lots with qtyOnHand, qtyReserved, and computed qtyAvailable.
/api/dxosWms:allocateFefoPOSTwrite, wmsExecutes FEFO reservation across thermal-compatible lots.
/api/dxosWms:issueStockPOSTwrite, wmsIssues physical inventory and transitions order lines to dispatched.
/api/dxosWms:holdLotByMktPOSTwrite, wmsComputes Arrhenius MKT and places lots into hold_mkt on threshold breach.
/api/dxosWms:releaseLotByQaPOSTwrite, wmsReleases hold_mkt or quarantined lots back to available after QA sign-off.

Arrhenius MKT Holds, QA Quarantine, and SLA Tracking ​

When IIoT telemetry or QA sampling checks lot exposure, dxosWms:holdLotByMkt reads samplesC from the request body or queries up to 500 recent temperature samples in latticeTelemetryPoints for the lot's assetEntityId. The threshold resolves in priority order: maxAllowedC -> lot.targetTempMaxC -> -15°C (when coldChainProfile === 'frozen' or targetTempMinC <= -15) -> 8°C.

MKT is calculated using the stabilized Arrhenius formulation with gas constant R = 0.008314472 kJ/(mol·K) and activation energy ΔH = 83.14472 kJ/mol. If mktCelsius > thresholdCelsius or forceHold === true, the handler executes four atomic actions:

  1. Transitions the lot to hold_mkt with holdReason, heldAt, and heldBy.
  2. Writes a quarantine entry in latticeDataQuarantine with reasonCode: 'MKT_THRESHOLD_EXCEEDED'.
  3. Appends wms.lot_mkt_hold to the Ed25519-signed latticeCryptoLedger.
  4. Emits a lot.held_mkt CloudEvent to latticeEventBus for downstream incident escalation.
bash
curl -X POST https://app.example.com/api/dxosWms:holdLotByMkt \
  -H "Authorization: Bearer ldx_pat_a1b2c3d4_..." \
  -H "Content-Type: application/json" \
  -d '{
    "lotCode": "LOT-2026-A09",
    "samplesC": [4.2, 5.1, 9.8, 10.4, 8.9]
  }'

In parallel, latticeSlaPolicies defines warning (warnAfterMinutes, default 240) and breach (breachAfterMinutes, default 1440) windows for orders and incident cases. When DX_SLA_CRON_ENABLED=true, the SLA evaluator runs every DX_SLA_INTERVAL_MS (60000 ms default) and escalates overdue records to escalateToRole (ldx_manager default) over configured notifyChannels. Inside portals, DxosWmsOpsBlockModel exposes interactive FEFO reservation and bulk import (MAX_BULK_IMPORT_BYTES = 2 MB), paired with DxosKanbanScheduleBlockModel for lot status boards.

Operational Controls, Error Codes, and Failure Modes ​

ControlRuntime BehaviorError Code / Outcome
Pessimistic row lockingFEFO allocation and stock issue acquire SELECT ... FOR UPDATE locks inside a transaction.Prevents concurrent orders from over-allocating beyond qtyOnHand - qtyReserved.
Multi-tenant isolationresolveTenantActor binds app.current_org from user session or ldx_pat_* API key.Returns 404 WMS_ORDER_NOT_FOUND or 404 WMS_LOT_NOT_FOUND on cross-org access.
QA release state checkdxosWms:releaseLotByQa only accepts lots in hold_mkt or quarantined.Returns 409 WMS_LOT_INVALID_STATE for other states; requires an explicit releaseReason.

The following error codes from wms-engine.js enable deterministic error handling in client portals and automated flows:

Error CodeHTTPTrigger ConditionRemediation
WMS_SKU_REQUIRED / WMS_QTY_INVALID400Missing sku or non-positive quantity (<= 0).Validate line item fields prior to calling allocateFefo.
WMS_ORDER_LINE_SKU_MISMATCH400Target orderLine already exists with a different sku.Use a new lineNo or match the existing line's sku.
WMS_LOT_ON_HOLD409Target lot is in hold_mkt, expired, quarantined, or past expiryDate.Release via QA (releaseLotByQa) or allocate an alternative lot.
WMS_INSUFFICIENT_STOCK409Issue quantity exceeds current qtyOnHand on the locked lot.Split the dispatch quantity or re-run FEFO allocation.
MKT_INVALID_SAMPLE400Sample is non-finite, <= -273.15°C, or deltaH <= 0.Filter out malformed sensor readings before computing MKT.
WMS_MKT_SAMPLES_REQUIRED400Empty samplesC, no asset telemetry, and forceHold !== true.Supply samplesC or bind a valid assetEntityId to the lot.

Apache-2.0 · LatticeDX v0.4.2 · Powered by NocoBase · v2.2.50 · Apache-2.0 (Clause 5.2)