# Stock governance rules

**Audience:** Operations, finance liaison, engineering leads.  
**Prerequisites:** [`stock-domain-principles.md`](stock-domain-principles.md), [`transaction-engine.md`](transaction-engine.md), [`inventory-invariants.md`](inventory-invariants.md), [`inventory-domain-rules.md`](inventory-domain-rules.md).

---

## Part 7 — Stock governance

### Stock correction rules

- **Never** “edit” `on_hand_qty` on a projection row without a corresponding **ledger movement** in the same audited transaction (exception: **controlled rebuild job** after incident commander approval).
- **Wrong receipt:** post compensating `stock_out` or reversal movement with reason code; do not delete original receipt line.
- **Data entry error same day:** compensating movement + ticket; optional `occurred_at` alignment with policy.

### Adjustment approval expectations

- **Materiality thresholds:** e.g. value or quantity above limit requires **manager** approval; above higher limit requires **finance** + second pair of eyes.
- **Segregation:** user who **counts** should not be sole approver of **posting** adjustment (configurable per tenant).
- **Evidence:** attachment or cycle count id stored in movement `metadata`.

### Reconciliation expectations

- **Periodic:** physical count vs projection by warehouse; variance generates **adjustment** movements only after approval.
- **Continuous:** integration of shipping confirmations vs `stock_out` — mismatch queue for ops.
- **SLA:** unresolved variance aged **> N days** escalates per tenant policy.

### Auditability guarantees

- Ledger **append-only**; projection changes only via known workers/services.
- **Who / when / why** on every adjustment and reservation release (activity log + movement metadata).
- **Replay:** engineering can reproduce balances from ledger export for auditors.

---

## Part 8 — Future compatibility (explicitly not built now)

Design **hooks** only — no accounting valuation, no full procurement/sales modules in this phase.

| Future domain | Compatibility hook |
|---------------|---------------------|
| **Accounting valuation** | Movements carry `item_id`, `quantity`, `unit_id`, `occurred_at`; **cost layers** attach later via `movement_id` FK from a separate `inventory_cost_layers` (or GL subledger) — **never** mix average cost into ledger quantity rows. |
| **Procurement** | `reference_type = purchase_receipt_line` on `stock_in`; three-way match reads ledger, not projections alone. |
| **Sales** | `reference_type = sales_order_line`; reservation → `stock_out` on ship confirm. |
| **Manufacturing** | `reference_type = work_order_component_issue` / `assembly_receipt`; BOM explosion outside stock core. |
| **Batch / lot tracking** | Optional future columns or child table `inventory_stock_lots` keyed by `movement_id` + `lot_code`; ledger remains per line with lot splits as **child movements** or lot-scoped projection rows. |
| **Expiry tracking** | Lot-level `expiry_date`; FEFO allocation policy in picking service — not in base ledger type enum. |
| **Serial tracking** | Table `inventory_serial_units` (serial, item_id, state) updated only via movements referencing serial ids. |

**Boundary:** Valuation **posts** consume movements as **inputs**; stock domain does not compute COGS.

---

<a id="part-9-self-validation"></a>

## Part 9 — Self-validation (governance + program)

- [x] Immutable ledger enforced (policy + technical controls described in principles doc).
- [x] Stock projections separated from truth (rebuild + transactional apply).
- [x] Reservations supported (reference + expiration-ready design).
- [x] Warehouse isolation supported (tenant + warehouse keys on movements and projections).
- [x] Concurrency strategy defined (transaction + pessimistic default + ordering).
- [x] Future ERP compatibility documented (valuation, procurement, sales, MFG, lot/expiry/serial as extensions).

---

## Critical reminder

Inventory corruption destroys trust fast.

**Ledger integrity > convenience · Traceability > shortcuts · Consistency > performance hacks**
