# Purchase Order — Models & Action Visibility Matrix

## Models Involved

Source of truth: `@tailor-platform/erp-kit` v0.17.0 (see `package.json`).

| Model | erp-kit model | Role in this flow |
|---|---|---|
| PurchaseOrder | `PurchaseOrder` | Document header; owns `orderStatus`, `receiptStatus`, `billingStatus` |
| PurchaseOrderLine | (see PurchaseOrder) | Per-line item, quantity, unit price |
| PurchaseOrderLineRevision | (see PurchaseOrder) | Immutable snapshot of a line before amendment |
| BusinessPartner | (item-management / supplier docs) | Supplier reference |

### Status Axes

| Field | Values |
|---|---|
| `orderStatus` | `DRAFT` → `SUBMITTED` → `ORDERED` → `CANCELLED` \| `CLOSED` |
| `receiptStatus` | `NOT_RECEIVED` → `PARTIALLY_RECEIVED` → `RECEIVED` (set on approval; advanced by `postInboundShipment`) |
| `billingStatus` | `NOT_BILLED` → `PARTIALLY_BILLED` → `BILLED` (set on approval; advanced as vendor invoices are registered against the PO) |

The state machine is owned by the native erp-kit `PurchaseOrder` model.

## Action Visibility Matrix

The `purchase-order-detail` screen's action panel gates each button on `orderStatus` plus, in one case, `receiptStatus`. Rendered by `purchase-order-actions.tsx`.

Legend: ✓ visible+enabled · ◐ visible but disabled · blank = hidden.

| Action | Resolver / target | DRAFT | SUBMITTED | ORDERED | CANCELLED | CLOSED | Extra condition | Role |
|---|---|:-:|:-:|:-:|:-:|:-:|---|---|
| Edit | _navigate to edit form_ | ✓ |  |  |  |  | — | purchaser |
| Submit for Approval | `submitPurchaseOrder` | ✓ |  |  |  |  | — | purchaser |
| Approve | `approvePurchaseOrder` |  | ✓ |  |  |  | — | approver |
| Reject | `rejectPurchaseOrder` |  | ✓ |  |  |  | requires reason | approver |
| Amend | _navigate to amend form_ |  |  | ✓ |  |  | — | purchaser |
| Create Inbound Shipment | `createRemainingInboundShipment` |  |  | ✓ |  |  | `receiptStatus ≠ RECEIVED` | purchaser |
| Close | `closePurchaseOrder` |  |  | ✓ |  |  | — | purchaser |
| Cancel | `cancelPurchaseOrder` | ✓ | ✓ | ✓ |  |  | backend additionally rejects if a posted inbound shipment exists | purchaser |
| Duplicate | `duplicatePurchaseOrder` | ✓ | ✓ | ✓ | ✓ | ✓ | — | purchaser |
| Back | _navigate to list_ | ✓ | ✓ | ✓ | ✓ | ✓ | — | — |
