# InventoryAdjustment

## Description

InventoryAdjustment represents a correction to on-hand stock quantities at a specific storage location. Each adjustment has an `adjustmentType` that determines its behavior:

- **CORRECTION**: Manual corrections to reconcile system records with physical reality — discrepancies from damage, theft, counting errors, receiving mistakes, or production variances. Confirmation generates a stock movement to/from a virtual "adjustment" location.
- **SCRAP**: Controlled disposal of damaged, expired, defective, or obsolete stock. Confirmation moves stock to a virtual "scrap" location, reducing inventory valuation. For serial-tracked items, the serial number transitions to SCRAPPED state.

Both types follow the same approval workflow: DRAFT → optionally PENDING_APPROVAL → APPROVED → CONFIRMED. Rejected adjustments can be revised back to DRAFT. Once confirmed, an adjustment is immutable — corrections require a new offsetting adjustment.

## Domain Model Definitions

### Model type

Stateful

#### State Transitions

```mermaid
stateDiagram-v2
    [*] --> Draft: createInventoryAdjustment
    Draft --> PendingApproval: submitInventoryAdjustment
    Draft --> Confirmed: confirmInventoryAdjustment (no approval needed)
    PendingApproval --> Approved: approveInventoryAdjustment
    PendingApproval --> Rejected: rejectInventoryAdjustment
    Rejected --> Draft: reviseInventoryAdjustment
    Approved --> Confirmed: confirmInventoryAdjustment
```

### Command Definitions

- [createInventoryAdjustment](../commands/CreateInventoryAdjustment.md) - Create a new inventory adjustment in DRAFT status
- [submitInventoryAdjustment](../commands/SubmitInventoryAdjustment.md) - Submit a draft adjustment for approval
- [approveInventoryAdjustment](../commands/ApproveInventoryAdjustment.md) - Approve a pending adjustment
- [rejectInventoryAdjustment](../commands/RejectInventoryAdjustment.md) - Reject a pending adjustment
- [reviseInventoryAdjustment](../commands/ReviseInventoryAdjustment.md) - Return a rejected adjustment to draft for revision
- [confirmInventoryAdjustment](../commands/ConfirmInventoryAdjustment.md) - Confirm an approved or draft adjustment, applying the quantity change

### Query Definitions

- [getInventoryAdjustment](../queries/GetInventoryAdjustment.md) - Retrieve an inventory adjustment by id
- [listInventoryAdjustments](../queries/ListInventoryAdjustments.md) - List inventory adjustments with optional filters

### Models

- InventoryAdjustment

### Invariants

- Reason code is required
- adjustmentType is required (CORRECTION or SCRAP)
- Draft adjustments do not affect on-hand quantities
- Confirmation generates a stock movement to update stock levels
- CORRECTION: stock movement to/from virtual adjustment location
- SCRAP: stock movement to virtual scrap location; quantityDelta must be negative
- SCRAP with serial number: serial transitions to SCRAPPED state on confirmation
- Negative adjustment cannot reduce on-hand below zero (unless the organization permits negative stock)
- Immutable after confirmation — corrections require a new offsetting adjustment
- Rejected adjustments do not affect stock levels or valuation
- Adjustments originating from a count session link back to the InventoryCount

### Relationships

- **References Item**: Each adjustment targets an Item from the item-management module
- **References StorageLocation**: Each adjustment targets a specific storage location
- **References InventoryCount (optional)**: Adjustments may be linked to an inventory count session (CORRECTION type only)
- **References Lot (optional)**: For lot-tracked items, the specific lot being adjusted
- **References SerialNumber (optional)**: For serial-tracked items, the specific serial number being adjusted
