# Shipment

## Description

Shipment is the sales-side fulfillment document that proves which order quantities were shipped, when they shipped, and from which site. It is the commercial fulfillment evidence for shipment-gated invoicing policies.

## Domain Model Definitions

### Model type

Stateful

#### State Transitions

```mermaid
stateDiagram-v2
    [*] --> Draft: createShipment
    Draft --> Posted: postShipment
```

| Operation | From | To | Command |
|-----------|------|----|---------|
| post | DRAFT | POSTED | [postShipment](../command/PostShipment.md) |

### Command Definitions

- [createShipment](../command/CreateShipment.md) - Create a draft shipment against open sales-order lines.
- [updateShipment](../command/UpdateShipment.md) - Correct draft shipment details such as quantities, addresses, or tracking data before posting.
- [postShipment](../command/PostShipment.md) - Post the shipment and update order progress.

### Query Definitions

- [getShipment](../query/GetShipment.md) - Retrieve one shipment with posted quantities, addresses, and tracking context.
- [listShipmentsBySalesOrder](../query/ListShipmentsBySalesOrder.md) - List shipments associated with a selected sales order.

### Models

- Shipment
- ShipmentLine

### Invariants

- Every shipment belongs to exactly one company and references exactly one sales order.
- Only DRAFT shipments may be edited directly.
- Only POSTED shipment quantities contribute to sales-order shipped progress or shipment-gated invoice eligibility.
- Posting a shipment must not create or post inventory stock movement records from sales.

### Relationships

- **Owns ShipmentLine**: Each shipment contains one or more shipment lines tied to order lines.
- **References SalesOrder**: `salesOrderId` identifies the originating commercial commitment.
- **References Site (cross-module)**: `shipFromSiteId` comes from organization and records fulfillment origin.
