# StockAdjustmentLine

## Description

StockAdjustmentLine represents a single item-location quantity change within a StockAdjustment. Each line specifies the item, storage location, quantity (always positive), and an adjustmentDirection (INCREASE or DECREASE) that determines whether the adjustment adds or removes stock. Lines optionally reference a Lot or SerialNumber for tracked items, and may include a unitCost for valuation purposes.

For SCRAP-type adjustments, a line optionally specifies `fromStockCategory` (AVAILABLE or BLOCKED) to indicate whether the stock being scrapped is drawn from the available pool or from blocked (quarantined) stock. When `fromStockCategory=BLOCKED`, confirming the adjustment creates a single InventoryLedger entry ({SCRAP, CR, stockType=BLOCKED}) and decrements the BLOCKED StockLevel type quantity. The default is AVAILABLE.

Lines are created as part of a StockAdjustment and are managed through the parent adjustment's lifecycle. When the parent StockAdjustment is confirmed, each line generates InventoryLedger entries linked to the StockAdjustment InventoryExecution, with a dcIndicator derived from the adjustmentDirection and category. Monetary impact is handled by valuation records using quantity and unitCost.

## Domain Model Definitions

### Model type

Standard

### Command Definitions

- StockAdjustmentLine records are created and updated through the parent StockAdjustment commands:
  - [createStockAdjustment](../command/CreateStockAdjustment.md) - Lines are provided when creating the adjustment
  - [updateStockAdjustment](../command/UpdateStockAdjustment.md) - Lines can be added, modified, or removed while the parent is in DRAFT or REJECTED status

### Query Definitions

- Stock adjustment lines are included in stock adjustment queries

### Models

- StockAdjustmentLine

### Invariants

- quantity is always positive (> 0)
- adjustmentDirection must be one of: INCREASE, DECREASE
- itemId is required — each line pertains to a specific item
- storageLocationId is required — the location where the adjustment occurs
- stockAdjustmentId is required — each line belongs to a parent StockAdjustment
- For serial-tracked items, quantity must be 1 per serial number
- unitCost is optional — used for valuation when provided
- `fromStockCategory` is optional and only meaningful when the parent adjustmentType is SCRAP; allowed values are AVAILABLE (default) and BLOCKED
- For BLOCK and UNBLOCK adjustments, `fromStockCategory` must not be set (these types operate on their own category by definition)
- For CORRECTION adjustments, `fromStockCategory` is ignored
- Lines can only be modified while the parent StockAdjustment is in DRAFT or REJECTED status

### Relationships

- **Belongs to StockAdjustment**: Each line belongs to a single StockAdjustment
- **References Item**: Each line references an Item from the item-management module
- **References StorageLocation**: The location where the adjustment occurs
- **References Lot (optional)**: For lot-tracked items, the specific lot affected
- **References SerialNumber (optional)**: For serial-tracked items, the specific serial number affected
