Create a DRAFT CapacityPlan and compute its shortage
POST/capacity-plans
Evaluates the ProcessPath path_id against assigned_demand (orders) for the warehouse's location over [window_start, window_end): loads each step's ProcessCapacity, normalizes it with the WorkloadProfile factors supplied in the body (same shape and validation as GET /process-paths/{id}/capacity -- there is no WorkloadProfile persistence yet), and computes path_capacity (ORDER per HOUR), bottleneck_step, capacity_over_window (path_capacity x window hours) and shortage (max(0, assigned_demand - capacity_over_window), never negative). The window is both the plan's planning window AND the window every step's ProcessCapacity is looked up for: a registered window applies to a step when it COVERS [window_start, window_end), exactly as in GET /process-paths/{id}/capacity (docs/adr/0003). The plan stores its own requested window. site_id is REQUIRED: the canonical site (a facility-layout Site site_code, the same identifier its SiteCapabilityChanged event publishes) the plan is scoped to. It is a stated planning fact, never inferred from warehouse_id or location, and a blank or absent one is rejected with 422 missing-required-field. assigned_demand is OPTIONAL (docs/adr/0004). An explicit value (including 0) is used exactly as stated and the plan's demand_source is "request". When it is OMITTED the demand defaults to the number of orders the local read model -- fed by order-management's published OrderAllocated / OrderPartiallyAllocated events, never by a live call -- expects at location in [window_start, window_end) (see GET /demand), the plan's demand_source is "orders", and assigned_demand in the response is that figure. When the read model has no order for that location and window the request is rejected with 422 missing-assigned-demand: absence never silently means zero demand. demand_source (docs/adr/0024) may name the source instead: "forecast" derives assigned_demand from the workload forecast of (site_id, forecast_path_id, default path_id) -- the units of the buckets whose cpt is in the window over units_per_order, rounded up to orders -- and the plan returns forecast_path_id. labour_requirement (docs/adr/0022) states, per path step, the labour its demand requires: tasks x the standard seconds of the step's task type, read from the local copy of labor-performance's labour standards (fed by its LaborStandardDefined / LaborStandardRevised events, never by a live call) for the plan's site at window_start. The optional tasks_per_order map counts a step's tasks; a step without a standard or without a task count is known false with a reason. It is informational: the shortage, the bottleneck and every published event are unchanged by it. The plan is saved and its CapacityPlanCreated event is queued in the transactional outbox in ONE database transaction.
Request
Responses
- 201
- 400
- 404
- 409
- 422
- 500
Plan created (status DRAFT).
Response Headers
Present, with the value "true", only when the answer is a replay of an earlier request with the same Idempotency-Key.
Malformed JSON body, malformed window_start/window_end, a window whose end is not after its start, or a missing/malformed Idempotency-Key (idempotency-key-required / idempotency-key-invalid).
No ProcessPath registered under path_id (process-path-not-found -- RETRYABLE: the ACTIVE flow arrives as a process-path-management event, so the refusal is not stored and the key is released; retry the SAME key once the path is known).
The Idempotency-Key was already used with a different request (idempotency-key-reused).
RETRYABLE (not stored, key released -- the state can arrive later): a path step has no ProcessCapacity registered for this location/window (missing-step-capacity); a WorkloadProfile factor is missing for a step's unit (missing-conversion-factor) or cannot normalize it (unsupported-normalization-unit); assigned_demand is omitted and the order-demand read model has no order yet for this location and window (missing-assigned-demand). FINAL (stored and replayed): a WorkloadProfile factor is not positive; assigned_demand is negative; a tasks_per_order value is not positive (non-positive-tasks-per-order); site_id is absent/blank; or warehouse_id/location/path_id is blank. demand_source (docs/adr/0024): an unknown value (unknown-demand-source), an input the source does not read (demand-source-conflict), demand_source forecast without units_per_order (missing-units-per-order) or with no forecast bucket in the window (missing-assigned-demand); a scenario label that is empty or longer than 64 characters (invalid-scenario).
An unexpected failure (a store or outbox error). Answered as problem+json (internal-error). A 5xx answer is never stored under an Idempotency-Key and rolls back the aggregate change and its outbox rows, so the retry re-executes.