Receiving and quality holds
How goods enter Karyo, what is checked on the way in, and what a hold actually holds.
The two shapes of inbound
There is one receiving path with two entry shapes, distinguished per line, not per receipt:
- Against expectation. The line names an
asnLineId. The ASN line supplies the product, the over-receipt guard runs against itsexpectedAmount, and the receipt is auto-bound to that line's parent ASN if it was not already. - Blind. The line names an
itemDataIdand no ASN line. Nothing is compared against an expectation.
GoodsReceiptService.resolveLineContext
(services/order-service/karyo-orders-core/.../service/GoodsReceiptService.kt, GoodsReceiptService.resolveLineContext) is the
fork. A line with neither field is a 422 (GoodsReceiptService.blindLineContext).
A goods receipt may span any number of ASNs (goods_receipt_asns, a join table). A scalar
asnId request field is still accepted, as an alias folded into the set
(GoodsReceiptService.resolveRequestedAsnIds).
The ASN
An Asn runs CREATED → RELEASED → STARTED → FINISHED, plus CANCELED, over the shared 18-value
OrderState (karyo-orders-api/.../vo/OrderState.kt, OrderState). Only RELEASED or STARTED ASNs
can be attached to a receipt; anything else is a 409
(GoodsReceiptService.requireAsnAttachable).
Cancellation is stricter than the shared state machine: AsnService.cancel refuses at or
past STARTED (AsnService.cancel), where OrderState.canAdvanceTo would allow it up to
PICKED. The narrower gate is deliberate - once a line has been received against, the ASN is
history, not a plan.
recordReceipt (AsnService.recordReceipt) advances a line CREATED → STARTED on first receipt
and → FINISHED when remaining hits zero, and pulls the ASN RELEASED → STARTED alongside.
Reversal takes the quantity back but never walks state backwards:
Deliberately does NOT walk line/ASN state backward -
OrderStateis forward-only, so a FINISHED line may end withreceivedAmount < expectedAmountafter a reversal; the quantity is the truth, the state is the history.
AsnService.retractReceipt. This is the clearest statement of the model's general posture: state
records what happened, quantities record what is. A consultant reading an ASN line's state to
decide whether more is expected will be wrong after a reversal; read remaining.
Unit-load pre-advice
An ASN may carry AsnUlAdvice rows - expected unit-load labels. On receipt, if the receipt has
any ASN attached, the resolved label is checked against every attached ASN's open advices
and silently matched (GoodsReceiptService.matchUlAdvice). A blind receipt with no ASN
attached never matches, and an unmatched label is a no-op by design: un-advised arrivals are
first-class and are never warned about. Reversing a line reopens the advice it matched
(GoodsReceiptService.reverseLine), so re-receiving the same physical pallet re-matches.
Receipt types
GoodsReceiptType is NORMAL(0) or RETOUR(1), fixed at create and immutable afterwards -
there is no update path and the update DTO has no such field
(karyo-orders-api/.../vo/GoodsReceiptType.kt, GoodsReceiptType, GoodsReceiptService.create).
RETOUR carries two rules, both enforced in the service rather than in the enum:
- No ASN binding. Customer returns do not arrive on supplier ASNs, so RETOUR plus any
requested ASN is a 422 (
GoodsReceiptService.validateReceiptType). - Inspected by default. A RETOUR line received without an explicit
lockTypedefaults toQUALITY_FAULT(103)(GoodsReceiptService.resolveLineLockType).
That default lives at the service, not in the StockReceiver SPI, and the reason is recorded:
the SPI stays a policy-free mechanism ("create stock, optionally locked") that inventory honours
without knowing receiving rules (GoodsReceiptService.resolveLineLockType).
What is checked before anything is written
ReceiveLineValidator runs every check before the first write
(.../service/ReceiveLineValidator.kt, ReceiveLineValidator):
| Check | Refusal | Where |
|---|---|---|
Lock type is one of {1, 103, 202, 203} |
422 | ReceiveLineValidator.validateLockType, ReceiveLineValidator.validateStorageStrategy |
storageStrategyId names a strategy owned by this client |
422 | ReceiveLineValidator.validateStorageStrategy |
| The product still exists | 422 on an ASN line, "invalid reference" blind | ReceiveLineValidator.resolveAsnLineProduct, ReceiveLineValidator.resolveBlindProduct |
lotMandatory satisfied |
422 | ReceiveLineValidator.validateReceiptConstraints |
bestBeforeMandatory satisfied |
422 | ReceiveLineValidator.validateReceiptConstraints |
bestBefore is not in the past |
422 | ReceiveLineValidator.validateReceiptConstraints |
Three of these are worth calling out.
An explicit UNLOCKED(0) is refused, not accepted as a no-op, "so 'no lock' has exactly one
spelling (omission)" (ReceiveLineValidator.validateLockType). STOCKTAKING(7) is refused too - it is nonsensical at
receipt.
A product deleted after the ASN was created fails the receive rather than skipping
validation, because "a vanished product must never become a constraint bypass"
(ReceiveLineValidator.resolveAsnLineProduct). The ASN-bound path loads the product for the same reason: trusting the ASN line's
denormalised item fields instead would make lotMandatory and bestBeforeMandatory
unenforceable exactly where most receiving happens (GoodsReceiptService.resolveLineContext).
There is deliberately no minimum-remaining-shelf-life threshold. The reason is recorded
rather than invented: shelflife on the product is a duration, not an acceptance threshold, and
the acceptance datum does not exist (ReceiveLineValidator.validateReceiptConstraints).
Over-receipt
Receiving more than an ASN line expects is governed by two levels, and the instance level is the stricter one.
OverReceiptGuard.check (.../service/OverReceiptGuard.kt, OverReceiptGuard) only fires when
receivedAmount + amount > expectedAmount. It then resolves
karyo.receiving.allow-over-receipt for the receiving client - a stored runtime property first,
the environment value, then the catalogue default (true) last - and refuses unless both the per-request
allowOverReceipt flag and the instance knob allow it.
The composition is one-directional by design: a per-request override can never widen the instance knob. The lookup only runs on an actual over-receipt, so the normal path gains no database read.
Finishing a receipt
finish (GoodsReceiptService.finish) promotes stock INCOMING → ON_STOCK through
StockReceiver.markOnStock, filtered to lines that are neither qaHold nor reversed.
qaHold is derived, not stored, and means any receive-time lock, not only a quality fault:
val qaHold: Boolean get() = lockType != null && lockType != LockType.UNLOCKED.code
.../domain/model/GoodsReceiptLine.kt, GoodsReceiptLine.qaHold
markOnStock independently skips locked and already-promoted units and logs a warning, so the
filter is belt-and-braces (.../service/DefaultStockReceiver.kt, DefaultStockReceiver.markOnStock).
Cancellation is only possible while no line holds received stock
(GoodsReceiptService.cancel), because stock cannot be un-received in bulk. A reversed line
holds none, so it does not count: once every line on a receipt has been received and then
reversed, the receipt can be cancelled. It stays on the receipt as a CANCELED receipt that
carries its reversed lines, which are the record of what was received and undone. Finishing
such a receipt is still allowed and still records a FINISHED receipt that received nothing, so
cancel it instead. A CANCELED receipt can therefore carry reversed lines, and a webhook
subscriber sees it on the receipt's state-change event.
Reversing a line
reverseLine (GoodsReceiptService.reverseLine) is a total undo that refuses unless it can
fully reverse. It:
- soft-deletes the stock via
StockReceiver.unreceive, guarded by an amount-equality check - any pick, partial consumption or manual adjustment since receipt makes the amount mismatch and refuses the whole reversal (DefaultStockReceiver.unreceive); - decrements the bound ASN line without walking its state backwards;
- cancels the putaway transport order in the same transaction, through a default-phase CDI
observer - if that task is already
STARTEDthe observer throws and the whole reversal rolls back (.../tasks/service/TaskService.kt,TaskService.onGoodsReceiptLineReversed); - reopens any unit-load pre-advice the line matched.
unreceive deliberately does not trash the emptied unit load, and the reason is worth
keeping: a reversal is a receiving correction, not a retirement, and the workflow re-receives
onto the same physical label immediately afterwards. Labels are globally unique and a
DELETABLE unit load refuses reuse, so auto-trashing would permanently burn the label
(DefaultStockReceiver.unreceive).
Terminal putaway tasks (FINISHED/CANCELED) do not block a reversal - "no live work can
conflict" - only an in-flight STARTED one does (TaskService.onGoodsReceiptLineReversed).
Quality holds
A hold is a lock on the stock unit, applied at receipt. There is no separate hold entity, no
hold reason table, and no inspection workflow. GoodsReceiptService's own class KDoc records
this as a known limitation (GoodsReceiptService): stock received with a lock type -
QUALITY_FAULT for a QA hold, say - stays INCOMING and locked after finish. Releasing it takes
a manual inventory unlock and a manual stock state change to ON_STOCK; there is no dedicated
release workflow, but completing those two calls raises the putaway receiving skipped (see
Releasing a hold).
Held stock is also skipped by auto-putaway at receipt: the observer returns early on
event.qaHold (TaskService.onGoodsReceiptLineReceived), so no transport order is created for
it until the hold is released.
Releasing a hold
The release is two REST calls per stock unit, against endpoints that exist for general inventory maintenance rather than for this purpose:
POST /api/v1/stock-units/{id}/lockwithUNLOCKED(.../api/v1/StockUnitResource.kt,StockUnitResource.setLock)POST /api/v1/stock-units/{id}/change-statewith 300 (StockUnitResource.changeState)
The two calls may come in either order. The one that leaves the stock unit ON_STOCK and
unlocked completes the release, and that is when the skipped putaway is raised:
StockServicefiresStockUnitReleasedEventin-process when a stock unit crosses from unusable to usable (StockReleasePublisher).- The orders module matches the stock unit to a held, unreversed receipt line and fires
GoodsReceiptLineReleasedEvent(HeldReceiptLineReleaseObserver), but only when the stock is usable at the dock without the putaway receiving skipped. That holds when any of three things is true: the stock leftINCOMING; the lock the call cleared is the line's receive-time lock (a pallet-unlock cascade clears exactly the pallet's lock code, so it matches a line held with that code); or the unit load still sits at the line's receive location, which covers a hold replaced by another lock, such as a count's, before the release finished. Anything else raises nothing: stock that did not come from a held receipt line (a receipt's own promotion at finish, a found-stock approval) and a lock toggle on stock already in storage (a stock count, a manual lock and unlock). - After the release commits, the tasks module creates the PUTAWAY task through the receipt's own
path (
HeldLineReleasePutawayObserver,TaskService.onGoodsReceiptLineReceived). It starts from where the unit load sits at release, keeps the line's storage strategy, and is one task per receipt line: a later hold and release of the same stock does not raise a second one. Reversing the line cancels it like any receipt putaway. If another line's putaway for the same unit load is open, or finished since this line was received, none is raised: one pallet is put away once, and that task moved or is moving the whole pallet, held stock included. A putaway that finished before this line arrived on the pallet does not count.
Until that putaway finishes, the released stock is ON_STOCK at the goods-in dock, and
findForSelection has no area predicate
(stock model), so an allocation in that
window can still pick from the dock.
The console's stock lock action sends only the first call. A hold released there leaves the stock
INCOMING and unlocked: not pickable, and with no putaway until the state change is made through
the API.
Configuration seams that do not exist yet
Two things a client will ask for on day one are per-request inputs rather than policy, and both are recorded as deferred rather than missing:
- Auto-putaway on receipt is always on for non-held lines - hardcoded, not a knob. Making it
tunable (disable / immediate versus deferred / per item category) is left to a future
ReceivingStrategy(TaskService.onGoodsReceiptLineReceived). lockTypeandallowOverReceiptare per-request, decided by the operator per line. If a strategic pattern emerges - vendor X always allows over-receipt, SKU Y always QA-holds - the recorded direction is to elevate them onto aReceivingStrategywith a resolver seam, and that is deferred (GoodsReceiptService.receiveLine).
Both are honest deferrals with a named shape. Neither exists, so per-vendor or per-SKU receiving policy is a caller responsibility.
Related
- Putaway and location finding - what happens to a received line next
- Stock model and states - the lock enums and the
INCOMINGstate