# ProductionOrder

## Description

ProductionOrder is the manufacturing control document that turns one planning decision into executable shop-floor work. It owns the produced item, planned quantity and dates, company or site scope, released snapshots of BOM and routing content, execution rollup from work orders, and the lifecycle that governs release, completion, technical completion, reopening, and administrative close.

## Domain Model Definitions

### Model type

Stateful

#### State Transitions

```mermaid
stateDiagram-v2
    [*] --> DRAFT: createProductionOrder
    DRAFT --> DRAFT: updateProductionOrder
    DRAFT --> RELEASED: releaseProductionOrder
    DRAFT --> CANCELLED: cancelProductionOrder
    RELEASED --> DRAFT: unreleaseProductionOrder
    RELEASED --> RELEASED: rescheduleProductionOrder
    RELEASED --> IN_PROGRESS: startWorkOrder
    RELEASED --> CANCELLED: cancelProductionOrder
    IN_PROGRESS --> IN_PROGRESS: reportWorkOrderProgress
    IN_PROGRESS --> COMPLETED: completeProductionOrder
    COMPLETED --> TECHNICALLY_COMPLETE: technicallyCompleteProductionOrder
    TECHNICALLY_COMPLETE --> IN_PROGRESS: reopenProductionOrder
    TECHNICALLY_COMPLETE --> CLOSED: closeProductionOrder
```

| Operation | From | To | Command |
|-----------|------|----|---------|
| release | DRAFT | RELEASED | [releaseProductionOrder](../command/ReleaseProductionOrder.md) |
| cancel | DRAFT, RELEASED | CANCELLED | [cancelProductionOrder](../command/CancelProductionOrder.md) |
| unrelease | RELEASED | DRAFT | [unreleaseProductionOrder](../command/UnreleaseProductionOrder.md) |
| startWorkOrder | RELEASED | IN_PROGRESS | [startWorkOrder](../command/StartWorkOrder.md) |
| complete | IN_PROGRESS | COMPLETED | [completeProductionOrder](../command/CompleteProductionOrder.md) |
| technicallyComplete | COMPLETED | TECHNICALLY_COMPLETE | [technicallyCompleteProductionOrder](../command/TechnicallyCompleteProductionOrder.md) |
| reopen | TECHNICALLY_COMPLETE | IN_PROGRESS | [reopenProductionOrder](../command/ReopenProductionOrder.md) |
| close | TECHNICALLY_COMPLETE | CLOSED | [closeProductionOrder](../command/CloseProductionOrder.md) |

### Command Definitions

- [createProductionOrder](../command/CreateProductionOrder.md) - Create a draft production request with planning data.
- [updateProductionOrder](../command/UpdateProductionOrder.md) - Revise mutable draft planning fields before release.
- [releaseProductionOrder](../command/ReleaseProductionOrder.md) - Freeze BOM and routing, create work orders, and open execution.
- [unreleaseProductionOrder](../command/UnreleaseProductionOrder.md) - Return a released order to draft when no execution evidence exists.
- [rescheduleProductionOrder](../command/RescheduleProductionOrder.md) - Move planned dates on a released order before execution starts.
- [cancelProductionOrder](../command/CancelProductionOrder.md) - Abandon the order before meaningful execution makes cancellation invalid.
- [completeProductionOrder](../command/CompleteProductionOrder.md) - Mark physical production complete after final reporting and receipt handoff.
- [technicallyCompleteProductionOrder](../command/TechnicallyCompleteProductionOrder.md) - Freeze execution and move the linked cost summary into review.
- [reopenProductionOrder](../command/ReopenProductionOrder.md) - Re-enable controlled execution after a technically complete or reviewed state.
- [closeProductionOrder](../command/CloseProductionOrder.md) - Perform final administrative close once the linked cost summary is settled.

### Query Definitions

- [getProductionOrder](../query/GetProductionOrder.md) - Retrieve one production order with snapshots, progress, and closeout status.
- [listProductionOrdersByStatus](../query/ListProductionOrdersByStatus.md) - List production orders for planning, execution, or closeout queues.

### Models

- ProductionOrder
- ProductionOrderMaterialRequirement
- ProductionOrderBomSnapshot
- ProductionOrderRoutingSnapshot
- ProductionOrderCostBaseline

### Invariants

- Every production order belongs to exactly one company and one execution site.
- The ordered item must be an ACTIVE manufacturable item and planned quantity must remain greater than zero.
- BOM and routing references selected at release must belong to the same company and site scope as the production order.
- Orders in `RELEASED`, `IN_PROGRESS`, `COMPLETED`, `TECHNICALLY_COMPLETE`, or `CLOSED` always carry immutable BOM and routing snapshots.
- `CANCELLED` and `CLOSED` orders reject further shop-floor execution updates.
- Entering `COMPLETED` requires the final output-reporting and receipt-handoff evidence required by policy.
- Entering `TECHNICALLY_COMPLETE` requires that no additional execution, rescheduling, or material issue is still expected.
- Entering `CLOSED` requires the linked [ManufacturingCostSummary](./ManufacturingCostSummary.md) to be in `SETTLED`.

### Relationships

- **References Item (cross-module)**: the produced item is an [Item](../../../item-management/docs/model/Item.md).
- **Belongs To Company and Site**: execution scope is defined by [Company](../../../organization/docs/model/Company.md) and [Site](../../../organization/docs/model/Site.md).
- **Snapshots BillOfMaterial**: release freezes one [BillOfMaterial](./BillOfMaterial.md) version and exploded component requirements.
- **Snapshots Routing**: release freezes one [Routing](./Routing.md) revision and operation plan.
- **Has Many WorkOrders**: released routing operations materialize into [WorkOrder](./WorkOrder.md) records.
- **Owns One ManufacturingCostSummary**: cost collection and variance review are tracked in [ManufacturingCostSummary](./ManufacturingCostSummary.md).
