# Stock Adjustment — Models & Action Visibility Matrix

## Models Involved

Source of truth: native `inventory.StockAdjustment` (erp-kit `inventory`).

| Model | erp-kit module | Role in this flow |
|---|---|---|
| StockAdjustment | (erp-kit `inventory`, native) | Document header; owns `adjustmentType`, `reasonCode`, `adjustmentDate`, `status`, and `rejectionReason` (set on reject) |
| StockAdjustmentLine | (erp-kit `inventory`, native) | Per-line `itemId`, `storageLocationId`, positive `quantity`, `adjustmentDirection` (CORRECTION), `fromStockCategory` (SCRAP), optional `unitCost` |
| StockLevel | (erp-kit `inventory`, native) | AVAILABLE / BLOCKED balances updated when an adjustment is confirmed |
| Item | (erp-kit `item-management`) | Line item reference |
| StorageLocation | (erp-kit `inventory`) | Line storage location reference |

### Status Axes

| Field | Values |
|---|---|
| `adjustmentType` | `CORRECTION` (per-line `adjustmentDirection` INCREASE / DECREASE on AVAILABLE) \| `SCRAP` (per-line `fromStockCategory` AVAILABLE / BLOCKED) \| `BLOCK` (AVAILABLE → BLOCKED) \| `UNBLOCK` (BLOCKED → AVAILABLE) |
| `status` (Document Status) | `DRAFT` → `SUBMITTED` → `CONFIRMED`, with `SUBMITTED` → `REJECTED`, `REJECTED` → `DRAFT` (resubmit), and `DRAFT` → `CANCELLED`. The status is displayed verbatim on every screen. |

The Document Status state machine is owned by native erp-kit `inventory`. Transitions: submit (`DRAFT → SUBMITTED`), confirm (`SUBMITTED → CONFIRMED`), reject (`SUBMITTED → REJECTED`), cancel (`DRAFT → CANCELLED`), resubmit (`REJECTED → DRAFT`). This template exposes create + submit + confirm + reject + cancel; the native `resubmit` transition (`REJECTED → DRAFT`) is available in the native lifecycle but is not surfaced by a resolver here. Line quantities are always positive; the `adjustmentType` and per-line direction/category determine the effect. No stock moves until the adjustment is confirmed.

## Action Visibility Matrix

The `stock-adjustment-detail` screen's action panel gates each button on `status`.

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

| Action | Resolver / target | DRAFT | SUBMITTED | REJECTED | CONFIRMED | CANCELLED | Extra condition | Role |
|---|---|:-:|:-:|:-:|:-:|:-:|---|---|
| Submit | `submitStockAdjustment` | ✓ |  |  |  |  | — | inventory-manager |
| Cancel | `cancelStockAdjustment` | ✓ |  |  |  |  | — | inventory-manager |
| Confirm | `confirmStockAdjustment` |  | ✓ |  |  |  | applies the stock movement (ledger entries + StockLevel updates) | approver |
| Reject | `rejectStockAdjustment` |  | ✓ |  |  |  | optional rejection reason | approver |
| Back to Stock Adjustments | _navigate to list_ | ✓ | ✓ | ✓ | ✓ | ✓ | — | — |

## Notes on Stock Movement

Stock is applied only by `confirmStockAdjustment`. Confirmation posts inventory ledger entries and updates the affected `StockLevel` rows: CORRECTION applies each line's `adjustmentDirection` to AVAILABLE, SCRAP writes off the line's `fromStockCategory`, BLOCK moves AVAILABLE → BLOCKED, and UNBLOCK moves BLOCKED → AVAILABLE. Confirmation fails with `INVENTORY_INSUFFICIENT_STOCK` when there is not enough stock to decrease, scrap, or block.
