Picking
A PickOrder is a container plus a list of Pick rows, each of which names one source stock
unit and a planned quantity. Everything in this document is about how those rows come into
existence, what a confirmation does, and what happens when the quantity is not there.
Generating pick orders
PickOrderService.releaseToPicking
(services/fulfillment-service/karyo-fulfillment-core/.../service/PickOrderService.kt, PickOrderService.releaseToPicking)
turns one delivery order's reservations into pick work.
- Refuse if the order is at or past
STARTED- "fail fast with a domain-correct 409 ... rather than doing work and leaning onmarkStarted's forward-only guard to roll it all back" (PickOrderService.releaseToPicking). - Flatten every line's
OrderLineReservationslices intoPlannedPicks (PickOrderService.flattenReservations). One slice, one planned pick. - Refuse if there are none: "no reserved stock to pick" (
PickOrderService.releaseToPicking). - Require a
PACK_STAGINGlocation; without one, release is refused (PickOrderService.releaseToPicking). - Group, fire the extension event, persist.
Partial reservations are pickable. The state gate is < STARTED, so a RELEASED order whose
lines are still PENDING releases whatever was reserved. That follows from the shortfall
model in allocation - the order is not blocked on
being fully covered - but it means "released to picking" does not imply "fully allocated".
Grouping and the extension seam
PickOrderGroupingStrategy decides how planned picks split into orders; the built-in is
DiscreteGroupingStrategy (one batch). For each resulting batch,
PickingOrderPrepareEvent fires after grouping and before any persistence - no container, no
PickOrder, no Pick row exists yet - and an observer may claim planned picks by index
(PickOrderService.firePrepareEventAndFilter). If an extension consumes every index, the whole batch is
refused with AllPicksConsumedByExtension and no pick order is created, "so the caller learns an
extension took the whole batch rather than silently getting an empty order" (PickOrderService.firePrepareEventAndFilter). Karyo
ships no built-in observer; it is a pure seam.
createTypeOrders on the strategy then splits each batch by picking type, producing separate
COMPLETE and PICK orders (PickOrderService.releaseToPicking). Off - the default - one batch is one pick order even
when the batch is type-mixed.
Saved pick route
The order strategy's proximityRoute option is off by default. When it and the Facility's
karyo.proximity.enabled are both on, each new pick order visits its reserved locations nearest
neighbour by walk metres from the first Area's entry. Lift metres break walk ties; equal legs keep
the input order. Unplaced locations follow by location orderIndex, then id. Zone corrections
apply through layout's shared distance service. Without either opt-in, creation order is unchanged.
Each pick stores its one-based sequence. Reads order by sequence with unsequenced picks last, then id; the floor app and
console follow that list. Picks that exist before the upgrade have no sequence and keep id order. Later layout or configuration
edits do not change an existing route; recovery and top-up work append (on an order created before the upgrade they stay unsequenced and append in id order). An extinguish order has
no order strategy and retains its old order.
Per-order wave picks use their order strategy. A cross-order zone batch, including bulk picks, uses proximity only when every contributing order requests it. Mixed batches keep their old order. Bulk lines follow the first pick for each source stock unit. This changes only the walk, never the stock reserved or the grouping of work (ADR 0062).
COMPLETE versus PICK
val full = sourceAmounts[pp.sourceStockUnitId]?.compareTo(pp.amount) == 0
return if (full) PickingType.COMPLETE else PickingType.PICK
PickOrderService.pickingTypeOf
A pick is COMPLETE when the planned quantity equals the source stock unit's whole amount.
Note this is the fulfillment PickingType (karyo-fulfillment-api/.../vo/PickingType.kt),
stored as a string on the Pick; the inventory module has a separate PickingType(PICK, COMPLETE)
enum with integer codes used by the selector's PickStockResult. They mean roughly the same
thing and are computed by different rules - the inventory one additionally requires the unit load
to be unopened, single-stock and COMPLETE-capable
(.../inventory/service/StockSelectionService.kt, StockSelectionService.determinePickingType).
PickOrderService.sourceAmountsFor builds the amount map from the chosen units only
(StockUnitLookup.sourceAmountsOf in SourceAmounts.kt):
val chosen = picks.mapTo(mutableSetOf()) { it.sourceStockUnitId }
if (chosen.isEmpty()) return emptyMap()
return findByIds(chosen, facility).associate { it.id to it.amount }
StockUnitLookup.sourceAmountsOf
That is one StockUnitLookup.findByIds(ids, facility) read of the source units, not every stock unit
of every ordered product. A caller looks an amount up only by a pick's sourceStockUnitId, so the
narrower map answers the same. WavePickService and PickTopUpService call the same function;
SourceAmountsTest pins it.
The container
Each pick order gets its own unit load as a pick container, created at the pack-staging location
with the pick-order number as its label (PickOrderService.persistPickOrder). Its type
defaults to the karyo.fulfillment.pick-bin-unit-load-type-id config value (seeded "Pick Bin",
id 2), overridable per request (PickOrderService.resolvePickBinTypeId).
There is a documented collision caveat: the generated pick-order number is checked for
uniqueness against PickOrderRepository, but the same string becomes the container's
labelId, and unit_loads.label_id is globally unique across all label sites. The uniqueness
check covers only the pick-order side, because fulfillment-core depends on
karyo-inventory-api, not -core, and UnitLoadLookup exposes no findByLabel. The label's
own collision risk is left to the database constraint, "same as every other generated label site
in the codebase that can't reach a same-module repository" (PickOrderService.persistPickOrder).
Confirming a pick
Confirmation shares cancellation's claim-conflict detector: principal UUID wins over the legacy
display snapshot, unclaimed work is allowed and no role, MANAGER included, bypasses the warning. A non-claimant
receives the non-leaking 409 pick-claim-warning-required problem before any mutation. Repeating
with acknowledgeClaimWarning: true explicitly accepts it; the same transaction writes the
audit event.
The claim itself is not transferred. The floor app offers acceptance online only, including bulk
confirmation, and never adds acknowledgement to a queued replay. Cancellation is unchanged.
The automatic dispatch claim path still skips already-taken candidates; it is not an interactive
claim-transfer operation.
confirmPick(pickId, pickedAmount, targetUnitLoadId, acknowledgeClaimWarning) (PickOrderService.confirmPick) accepts any amount in
(0, plannedAmount]. Over-picking is refused; short-picking is normal.
The terminal guard is state >= PICKED, which covers CANCELED(800) as well as PICKED(600),
and the comment names the failure it prevents: with a PICKED-only check, a stray or retried
confirm on a cancelled pick "would sail through, moving stock via pickStock with NO backing
reservation (potentially consuming a DIFFERENT order's reservation that re-claimed the freed
stock), driving the completion predicate below to reassign a CANCELED order back to PICKED, and
firing markPicked/outbox for an order the business believes canceled" (PickOrderService.confirmPick).
Then, in order:
- Capture actuals.
pickedLotNumberandpickedBestBeforeare read from the source stock unit beforepickStockmutates or consumes it - "the durable record of what was picked, independent of whatever the source stock unit becomes afterwards" (PickOrderService.confirmPick). A missing content ref leaves bothnull; the KDoc is explicit that this is an honest gap, "never fabricated" (PickOrderService.captureActuals). - Move the stock.
StockPicker.pickStockreleases the source's reservation for the picked quantity first, so the transfer - which validatesavailableAmount- can draw goods reserved for this order, then transfers and flips the freshly created target stock toPICKED(.../inventory/service/DefaultStockPicker.kt,DefaultStockPicker.pickStock). Fulfillment never touches reservations directly. - Recover any shortfall (below).
- Complete the pick order if every pick is now terminal, and advance the delivery order if every sibling pick order is too.
Order completion is sibling-aware
Because createTypeOrders can mint more than one pick order per delivery order,
finishPickOrderIfDone (PickOrderService.finishPickOrderIfDone) only calls markPicked when every
non-cancelled sibling has independently reached its own terminal state
(PickOrderService.allSiblingsComplete).
The reason is recorded and is a good example of how a small strategy flag creates a real
failure mode: markPicked is deliberately strict, not idempotent, so the second sibling to
finish would call it a second time, canAdvanceTo would refuse the same-state transition, and
"the WHOLE confirmation (incl. the stock move that already happened) rolls back, forever - the
first sibling's PICKED write is durable, so a retry fails identically" (PickOrderService.finishPickOrderIfDone).
Wave-linked orders take a different route entirely: completion is decided per confirmed pick,
through the pick's own owning order resolved from its line, because a batch pick order carries
no deliveryOrderId and a PICK_ONLY member order may own no per-order pick order at all
(PickOrderService.advanceWaveMemberOrderIfDone).
Short picks
A confirm below the planned amount runs recoverShortfall (PickOrderService.recoverShortfall), which forks on whether
the pick order is order-bound:
- Not order-bound (an
EXTINGUISHorder, or a cross-order wave batch order) - release the uncommitted reservation and stop. There is no follow-up, no substitution and no shortfall report. For batch picks this is deliberate: a wave's shortage recovery happens when the wave is allocated, where its own shortage handling reports the dropped lines, not on the floor (PickOrderService.recoverShortfall). - Order-bound - run
handleShortfall.
handleShortfall (PickOrderService.handleShortfall) does four things:
- Release the unpicked reservation.
- Ask the
PickDifferenceStrategywhat to do with the short source's residual. The built-in isLEAVE: leave it on the bin, but exclude it from the re-selection so the follow-up sources from elsewhere. - Apply the order's
ShortPickMode-FOLLOW_UP,FOLLOW_UP_THEN_SUBSTITUTE(the default),SUBSTITUTE_ONLYorNONE(karyo-orders-api/.../vo/ShortPickMode.kt,ShortPickMode) - creating follow-upPickrows for whatever can be re-reserved. - Hand any still-uncovered remainder to the
ShortfallStrategy. The built-in isPARTIAL_SHIP: report the shortage and accept it.
Exclusion is per confirm, not per chain: a follow-up pick that itself confirms short excludes
only its own source, not the original short source earlier in the chain. That is bounded because
the chain still terminates at the shortfall strategy, and the KDoc says so
(PickOrderService.handleShortfall).
Two things about follow-ups deserve attention.
The exclusion holds under every strategy flag. coverWithFollowUps passes excludeStockUnitIds
alongside the strategy's preferMatching and completeHandling (PickOrderService.coverWithFollowUps), and the selector
applies the exclusion in both pre-passes as well as the baseline passes. The follow-up never
re-selects the source that just came up short. Under completeHandling, if no other complete unit
load fits, there is no follow-up and the remainder moves on to substitution (if the mode allows it)
and then to the ShortfallStrategy. See
allocation.
A substitution follow-up carries the substitute's own article number. The follow-up of a substitute
is a different product, so coverWithFollowUps reads the substitute's number from
ProductLookup.findNumbersByIds and stamps it on the pick (PickOrderService.coverWithFollowUps). A
same-item follow-up copies its parent's number. PickResponse.itemDataNumber is served straight from that
field (.../api/v1/dto/PickDtos.kt, PickResponse, PickResponse.from), so the console pick pane, the floor
app's scan check, the packing unit and the shipping documents all name the article in hand, and
substitutedItemDataId marks the pick as a substitution. The order line keeps the ordered article's
number; its substitutedAmount is counted apart from pickedAmount. A pick a substitution created before
this change keeps the ordered article's number. A registered substitute whose product no longer resolves (for
example a deleted product) is skipped before anything is reserved: the short confirm still succeeds and the
remainder goes to the next substitute or the ShortfallStrategy.
Lot handling on a follow-up is correct and deliberate: a same-item follow-up re-selects within
the parent's lot and stamps it; a substitute is a different product with its own lots, so neither
the lot restriction nor the stamp is applied (PickOrderService.coverWithFollowUps).
Cancelling
Two granularities, both in PickLifecycleService.
Per line - cancelPick marks one pick CANCELED and releases its reservation.
Order level - forceFinish (PickLifecycleService.forceFinish) cancels every open pick,
releasing each outstanding reservation through the same path a short-pick release uses, then
lands the order on:
CANCELEDif no pick was ever genuinelyPICKED, orPICKEDif at least one was.
The PICKED outcome is intentional - "you pack what was picked" - and the short signal lives on
the delivery order's derived line rollup rather than on the pick order's state machine
(PickLifecycleService.cancelOrder). The count is of picks in state PICKED exactly, not "not open", so an order whose
picks were all cancelled per line still lands on CANCELED (PickLifecycleService.forceFinish).
Force-finish deliberately does not drive the delivery order anywhere. The rollup reads
PICKED picks only, so a cancelled pick simply never contributes and the derived figure
self-corrects (PickLifecycleService).
Force-finish can skip PICKED
The delivery order therefore stays at STARTED(500) after a force-finish. If the pick order
landed on PICKED, packing is openable, and PackingService.pack ends by calling
markPacked, which is progressIfBehind and so performs STARTED(500) → PACKED(650) in one hop
(.../orders/service/DefaultOrderProgressionPort.kt, DefaultOrderProgressionPort.markPacked, DefaultOrderProgressionPort.progressIfBehind).
OrderState.canAdvanceTo is forward-only, not step-by-step, so this is legal by construction and
nothing flags it. A delivery order can therefore reach SHIPPED having never been PICKED.
Anyone filtering or reporting on state == PICKED to mean "picking is done" will miss these.
The mechanism is deliberate; whether this particular outcome is intended is not recorded.
The one pairing that is guarded is a cancelled delivery order with a PICKED pick order -
which the cancel cascade produces in a single call. PackingService.openPacking closes it with a
guard keyed on the delivery order's state rather than the pick order's
(.../service/PackingService.kt, PackingService.openPacking).
Extinguish picks
ExtinguishService (.../service/ExtinguishService.kt, ExtinguishService) generates stock-clearance picks:
one Pick per stock unit for its full availableAmount, or every stock unit on a unit load,
reserved before the row exists.
There is no OrderStrategy and no DeliveryOrder. PickOrder.deliveryOrderId == null is the
marker, the order number is prefixed EXT-, and every pick is stamped
pickingType = "EXTINGUISH". An open extinguish order for the same client is topped up rather
than duplicated.
The null deliveryOrderId is what routes an extinguish short-confirm down the release-only
branch, and wave batch pick orders use the same marker. That is worth knowing because it means
deliveryOrderId == null on a pick order has two different meanings depending on whether
waveId is set.
One consequence of pickingType = "EXTINGUISH" being a string on the row: the
demand-forecasting engine reads karyo.picks directly and filters picking_type <> 'EXTINGUISH'
in native SQL, so renaming the literal would break a reader elsewhere in the build. See
the couplings the module graph does not show.
Waves, briefly
The wave engine adds wave-based bulk fulfilment. The pick-order side of it is
WavePickService, and its interaction with this document is limited to three things:
- a wave-linked pick order carries
waveId, and may or may not carrydeliveryOrderId; HYBRIDmode routesCOMPLETElines to ordinary per-order pick orders andPICKremainders to cross-order batch orders, which ride the same tasks board as normalPICKwork - no newWorkType;- every confirm on a wave-linked pick fires
WavePickActivityEvent, not only completions, because a wave progress UI wants live activity (PickOrderService.fireWaveActivityEventIfLinked).
Wave internals - selection rules, allocation shortage actions, consolidation, sort stations - belong to the wave engine and are not described here.
Related
- Allocation and reservation - where planned picks come from
- Packing and shipping - what a completed pick order becomes
- Work allocation - how a pick order reaches an operator
- Engine capabilities - what the wave engine adds