Skip to content

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_qt must equal batch.qt_total (raise ValueError otherwise)
  • Job stage is not closed

State Changes (Transaction)

Collections: Inherited from BaseProductionEvent.get_tx_collections()

  • Batch updated: marked completed, qt_total confirmed
  • Job updated: qt_completed incremented
  • StepExecutionData written if info.step_data provided and step-check is inactive
  • Serial records linked/released via SerialLinkedEvent / SerialReleasedEvent child events
  • Inventory movements triggered via MovementCompletedEvent child events for consumption/production
  • WIP records removed via WIPRemovedEvent / WIPDeclaredEvent child events
  • Work session closed via WorkSessionClosedEvent child event
  • If last batch: JobClosedEvent spawned as child
  • If continuation: BatchCreatedEvent + WorkSessionCreatedEvent spawned as children

Side Effects (post_processing)

Inherits post_processing() from BaseProductionEvent:

  • Updates job.last_online
  • Recalculates work order status; spawns WorkOrderClosedEvent if WO transitions to closed
  • Publishes to progress.notification.production

InfoModel Fields

FieldTypeDescription
active_batch_keystrKey of the active batch to complete
completed_batch_qtfloatQuantity declared as completed (must match batch total)
step_datalist[ExecutionDataUpdate] | NoneStep execution data to store if step-check is inactive
batch_serial_keyslist[str] | NoneSerial keys associated with this batch
job_keystr | NoneJob key (resolved from batch if not provided)
work_order_keystr | NoneWork order key (resolved from batch if not provided)

Source

BatchCompletedEvent on GitHub

Released under the Apache 2.0 License.