ADR 0014: Received stock is published per item
Status
Accepted (2026-11-09).
Context
Network gap G51: received seller stock never becomes a listing.
offer-availability is ready to create owner-scoped listings when it sees
received stock, but
com.retailnetwork.partner.seller-inbound.inboundshipment.InboundShipmentReceived
carries only {shipmentId, sellerId, nodeId, status, cartons:[{sscc, status}], receivedAt}: no item, GTIN or quantity. This context knows the manifest
content of every carton (Content: catalogItemId, gtin, qtyEaches, lot,
expiry) from labelling, the vendor's counted items per carton from
InboundReceiptSubmitted, and the catalogue packaging (GTIN to
catalogItemId, child GTIN, unitsPerPack) in its CatalogPackagingView
(ADR 0003).
Alternatives weighed:
- offer-availability joins
InboundShipmentLabelled(the manifest) withInboundShipmentReceiveditself. Rejected: it would have to keep a manifest read model of a context it does not own, could not see the vendor's counted quantities (they never leave this context), and would repeat the receipt-status rules of ADR 0002 (A8). - A new event (
InboundStockReceived). Rejected: the fact is the same closing fact; an additive optional field of the existing v1 payload is the smaller change and old consumers ignore it.
Decision
The contract, as fixed by the orchestrator (verbatim):
- InboundShipmentReceived.data gains
received: an array of {catalogItemId?, gtin, qtyEaches}, aggregated per (gtin) over the cartons whose receipt counts as received (define it from the as-built carton receipt status vocabulary, e.g. RECEIVED/RECEIVED_WITH_DISCREPANCY count and MISSING does not).- qtyEaches is in eaches: a case GTIN's qty x unitsPerPack, resolved from CatalogPackagingView. Use the receipt's ACTUAL counted quantities where the receipt reports them; otherwise use the manifest quantities. State the rule in the ADR.
- The
gtinis the EACH-level GTIN when the packaging view resolves the case GTIN to its child each. Otherwise it is the carton's GTIN. - catalogItemId is present when the packaging view resolves it, and omitted otherwise.
- Entries with qtyEaches 0 are omitted. Lines are sorted by gtin.
- The existing fields are unchanged.
receivedis always present on new events (an empty array is legal). Old consumers ignore it. - Update apis/asyncapi.yaml: payload schema, example, and description ('Consumers: offer-availability uses
receivedto create owner-scoped listings, gap G51'). If the catalogue ADR lists payload fields, update it there too. ADR (expected 0014): 'Received stock is published per item'. - Tests:
- domain/use-case tests for the aggregation: case vs each, a discrepancy carton, a missing carton, unresolved packaging;
- an encoder golden;
- the e2e/integration expectations for the event payload.
- Do not change the topic, type or subject.
How this context meets it, against the as-built model:
- Which cartons count. The as-built receipt vocabulary is
RECEIVED,MISSING,UNEXPECTED,DAMAGED(ADR 0002, A8); there is noRECEIVED_WITH_DISCREPANCYstatus. A carton with a quantity discrepancy is aRECEIVEDcarton whose counts differ from its manifest (Short/Over). Only manifest cartons answeredRECEIVEDcount, discrepant or not.MISSINGdoes not count (nothing arrived).DAMAGEDdoes not count: the stock is not sellable, and a listing on it would promise what cannot ship; the damage is already published asInboundDiscrepancyRecorded(Damaged).UNEXPECTEDdoes not count: a carton the manifest does not list has no known owner-of-record contents (only its SSCC is kept). - Quantity rule. For a counted carton, when the vendor's receipt
reported counted items for it (a non-empty item list), the counted
quantities are used, GTIN by GTIN, including a GTIN the manifest did not
list; otherwise the carton's manifest contents are used. Both are already
in eaches: a manifest
Content.QtyEachesis eaches by construction (aHOMOGENEOUS_CASEcarton'sqtyEachesmust equal theunitsPerPackof its active CASE level,ErrCaseQtyMismatchesGtin), and the receipt's countedqtyEachesis eaches on the wire. So the case GTIN'sqty x unitsPerPackIS the storedqtyEaches; it is summed as is, never multiplied again. - GTIN resolution. A line's GTIN is looked up in the
CatalogPackagingViewrows of the line'scatalogItemId: the manifest content'scatalogItemId; for a counted GTIN, thecatalogItemIdof the carton's manifest line with that GTIN, else of any manifest line of the shipment with that GTIN, else none (unresolved). From the row of that GTIN, thechildGtinchain is walked down inside the item's rows until a row of levelEACHis reached; its GTIN is the publishedgtin. When the chain breaks (no row for the GTIN, no child, a child the view does not hold) the carton's GTIN is published. Retired rows still resolve: retirement stops new packing at a level, it does not change which item a GTIN identifies.network.ResolveEachholds the rule. - catalogItemId. Present when the view holds a row of
(
catalogItemId, carton GTIN) at any level; omitted otherwise. When two contributions of one publishedgtindiffer, the first resolved one (in manifest carton order) wins. - Aggregation. Quantities are summed per published
gtin; entries withqtyEaches0 are omitted; lines are sorted bygtin. The array is always present ([]when nothing counts, for example every cartonMISSING). - Where it is computed.
Shipment.RecordReceiptbuildsreceivedwhen the shipment closes (InboundShipmentReceived.Received); the use caseApplyInboundReceipthands it a resolver over the localCatalogPackagingView(read only when the shipment closes, in the same transaction; no synchronous call to another context). EachCartonkeeps the vendor's counted items (Counted) from its first answer, in thecartonsJSONB column, so a shipment received over several receipts still publishes the actual counts. No migration: the column is JSONB and the new key is omitted when empty; a carton answered before this change has no stored counts and falls back to its manifest. - Topic,
type,subject,dataschema(:v1) and every existing field are unchanged. ADR 0004 lists no payload fields, so it is not edited.
Consequences
- offer-availability can create owner-scoped listings from the closing
fact alone (
sellerId,nodeId,received), gap G51. - A shipment closed before this change was published without
received; consumers must treat a missingreceivedas "unknown", not as "nothing received". Replays of those old events carry no lines. - Packaging declared after a shipment closed does not change the published lines; the event is a fact of the closing instant.
- Stock answered
DAMAGEDnever becomes a listing through this event; if damaged stock is later reworked into sellable stock, that is a new fact of the receiving node, not of this context. - Model gap G65 (plan lines may name a discontinued item) is out of scope.