# Order states & lifecycles

Path: `/guide/order-states`
Summary: The state machines you poll and interpret across every flow

Every flow in PULPO is a state machine. Your integration's job is to **read the current
state, wait for the transition that matters, and react** — usually via a webhook, sometimes
by polling. This page is the reference for the state values you will see and what each one
means. All values here are the exact strings the API returns.

> **NOTE: Where workflow state lives**
>
> The picking / packing / shipping workflow state lives on the **fulfillment order**, not the
> sales order header. A sales order always has at least one fulfillment order. Derive the
> effective state as `fulfillment_orders[0].state || sales_order.state`.

## Sales order lifecycle

A sales order (outgoing) walks a linear path from creation to Post Goods Issue:

```
queue ──→ picking ──→ packing ──→ shipping ──→ ended   (PGI — fulfilled)
  │
  ├──→ paused (on the fulfillment order) ──→ queue   (on resume)
  │
  └──→ cancelled   (from queue; also from picking/packing while cancellable)
```

| State       | Meaning                                                                  | Terminal? |
| ----------- | ------------------------------------------------------------------------ | --------- |
| `queue`     | Created, waiting to be picked                                            | no        |
| `picking`   | Items are being picked in the warehouse                                  | no        |
| `packing`   | Items are being packed into boxes                                        | no        |
| `shipping`  | Packed and ready for shipment                                            | no        |
| `ended`     | Fully fulfilled — Post Goods Issue (PGI)                                 | **yes**   |
| `paused`    | Temporarily held — set on the **fulfillment order**, not the sales order | no        |
| `cancelled` | Cancelled                                                                | **yes**   |

> **WARNING: Cancellation is state-dependent**
>
> An order in `ended` **cannot** be cancelled. An order in `picking` cannot be cancelled when
> there are no available packing locations. Don't assume cancel always succeeds — check the
> response.

**Endpoint: Search sales orders** — `GET /sales/orders` (operationId: searchSalesOrders)

Poll order state with `view_attributes=id,order_num,state` to keep responses small. Prefer
the `sales_order_finished` webhook over polling when you can.

### Priority levels

Sales orders carry a numeric `priority`: `1` = Low, `2` = Normal, `3` = High, `4` = Top.

## Picking order lifecycle

A picking task is one picker walking the floor. Picking operates on **fulfillment order
IDs**, not sales order IDs.

| State       | Meaning                              |
| ----------- | ------------------------------------ |
| `queue`     | Created, awaiting a picker           |
| `taken`     | Claimed by a picker                  |
| `ended`     | All items picked                     |
| `mixed`     | Partially picked — some lines remain |
| `cancelled` | Cancelled, items returned to stock   |

**Endpoint: List picking orders** — `GET /picking/orders` (operationId: listPickingOrders)

## Packing order lifecycle

A packing task is created by the system after picking completes. Ownership is the tricky
part — a user may own only **one** active (`taken` or `locked`) packing order at a time.

```
queue ─accept─→ taken ─lock─→ locked
                 │ ↑            │
                 │ └──unlock────┘   (owner → taken; non-owner → queue)
                 │
                 └─finish─→ ended ─close─→ closed
```

| State       | Meaning                                                             |
| ----------- | ------------------------------------------------------------------- |
| `queue`     | Awaiting a packer                                                   |
| `taken`     | Owned by a packer (see `owner.id`)                                  |
| `locked`    | Paused — kept by the owner but not actively worked                  |
| `ended`     | All boxes closed and `/finish` was called                           |
| `closed`    | Final — `/close` released the lock and assigned a shipping location |
| `cancelled` | Cancelled (terminal)                                                |

> **NOTE: Finding a user's current task**
>
> `GET /iam/users/{id}/tasks` returns a user's active task — but **not** `locked` (paused)
> ones. Query those separately with `GET /packing/orders?state=locked`. If a non-owner calls
> `/unlock` on a locked task it returns to `queue` (not `taken`) and must be re-accepted.

**Endpoint: List packing orders** — `GET /packing/orders` (operationId: listPackingOrders)

## Purchase order (incoming) lifecycle

Purchase orders, returns and warehouse movements all use the same order object,
distinguished by `type` (`purchase_order`, `return`, `warehouse_movement`).

| State                | Meaning                              |
| -------------------- | ------------------------------------ |
| `queue`              | Created, awaiting receiving          |
| `checking`           | Goods are being received / inspected |
| `finished_partially` | Closed with a partial receipt        |
| `closed`             | Fully received (Goods Receipt)       |
| `cancelled`          | Cancelled                            |

Receiving events (`incoming_goods`) record per-item outcomes. For returns and
quality-control, each received item carries its own `state` of `accepted` or `rejected`.

**Endpoint: List purchase orders** — `GET /reception/purchase_orders` (operationId: listPurchaseOrders)

## Shipment tracking status (label provider)

When an external system generates labels, the packing box's `shipment_tracking.status`
walks this machine:

| From                                | To                                  | Meaning                           |
| ----------------------------------- | ----------------------------------- | --------------------------------- |
| `null`                              | `pulpowms_label_generation_started` | Generation in progress            |
| `pulpowms_label_generation_started` | `pulpowms_label_generated`          | Success — tracking info available |
| `pulpowms_label_generation_started` | `pulpowms_label_generation_failed`  | Failure — see `error_message`     |
| `null`                              | `pulpowms_label_not_required`       | Skip label for this box           |

> **TIP: The real readiness signal**
>
> Label readiness is the presence of `attachments[0].url` on the packing box — not
> `shipment_tracking.status` alone. Poll `GET /packing/orders/{id}` every \~5s for up to \~2
> minutes (24 attempts), the same budget the PULPO app uses. Full walkthrough on the
> [Shipping Label Provider](/label-provider/shipment-tracking) track.

---

Website version: https://connect.pulpo.co/guide/order-states
Whole guide in one file: https://connect.pulpo.co/llms-full.txt
Index of all pages: https://connect.pulpo.co/llms.txt
