BatchCompletedEvent
EventType: BATCH_COMPLETEDDomain: production Broker subject: progress.notification.production
Records completion of an active batch against a job: validates that the declared quantity matches the batch total, stores step execution data, handles serial linking/releasing, triggers inventory movements for consumed and produced materials, and either closes the job (last batch) or creates a new batch (continuation).
Sequence Diagram
See also: the BatchCompleted -> child-batch-spawn fan-out diagram illustrates how this event spawns the next-phase batch when remaining production quantity is non-zero (per EVT-05 decomposition rule).
Trigger
Triggered by: POST /event (universal event dispatcher)
Dispatched via POST /event in backend/api/endpoints/traceability.py with event_type: BATCH_COMPLETED. Also spawned as a child event by StepCompletedEvent when all steps in the batch are marked done.
Preconditions
- Batch exists with key
info.active_batch_key info.completed_batch_qtmust equalbatch.qt_total(raiseValueErrorotherwise)- Job
stageis notclosed
State Changes (Transaction)
Collections: Inherited from BaseProductionEvent.get_tx_collections()
Batchupdated: marked completed,qt_totalconfirmedJobupdated:qt_completedincrementedStepExecutionDatawritten ifinfo.step_dataprovided and step-check is inactive- Serial records linked/released via
SerialLinkedEvent/SerialReleasedEventchild events - Inventory movements triggered via
MovementCompletedEventchild events for consumption/production - WIP records removed via
WIPRemovedEvent/WIPDeclaredEventchild events - Work session closed via
WorkSessionClosedEventchild event - If last batch:
JobClosedEventspawned as child - If continuation:
BatchCreatedEvent+WorkSessionCreatedEventspawned as children
Side Effects (post_processing)
Inherits post_processing() from BaseProductionEvent:
- Updates
job.last_online - Recalculates work order status; spawns
WorkOrderClosedEventif WO transitions to closed - Publishes to
progress.notification.production
InfoModel Fields
| Field | Type | Description |
|---|---|---|
active_batch_key | str | Key of the active batch to complete |
completed_batch_qt | float | Quantity declared as completed (must match batch total) |
step_data | list[ExecutionDataUpdate] | None | Step execution data to store if step-check is inactive |
batch_serial_keys | list[str] | None | Serial keys associated with this batch |
job_key | str | None | Job key (resolved from batch if not provided) |
work_order_key | str | None | Work order key (resolved from batch if not provided) |
Related Events
JobClosedEvent— spawned when batch completes the last required quantityBatchCreatedEvent— spawned when job continues with a new batchWorkSessionClosedEvent— spawned to close the current work sessionWorkSessionCreatedEvent— spawned if a new batch is createdSerialLinkedEvent— spawned to link serials to parent/batchSerialReleasedEvent— spawned to release serials on completionMovementCompletedEvent— spawned for PRODUCTION and CONSUMPTION movementsWIPDeclaredEvent— spawned to declare WIP at phase boundaryWIPRemovedEvent— spawned to remove WIP consumed by this batch