# SubmitStockAdjustment

## Permission Scope

inventoryControl

## Overview

submitStockAdjustment transitions a stock adjustment from DRAFT to SUBMITTED status. This submits the adjustment for review by an authorized approver. No stock, ledger, lot, serial, or valuation changes occur at this stage; the adjustment lines are frozen into a DRAFT InventoryExecution and can no longer be modified.

## Business Rules

- Stock adjustment must exist
- Stock adjustment must be in DRAFT status
- Creates a DRAFT InventoryExecution with effectiveDate copied from StockAdjustment.adjustmentDate
- Expands each StockAdjustmentLine into normalized InventoryExecutionLine effects
- Transitions status from DRAFT to SUBMITTED
- No stock, ledger, lot, serial, or valuation changes occur

## Process Flow

```mermaid
flowchart TD
    A[Submit stock adjustment request] --> B{Adjustment exists?}
    B -->|No| C[Return error: STOCK_ADJUSTMENT_NOT_FOUND]
    B -->|Yes| D{Status is DRAFT?}
    D -->|No| E[Return error: INVALID_STATUS]
    D -->|Yes| F[Create DRAFT InventoryExecution]
    F --> G[Create InventoryExecutionLine effects]
    G --> H[Transition to SUBMITTED]
    H --> I[Return updated stock adjustment]
```

## External Dependencies

- [inventory::StockAdjustment](../model/StockAdjustment.md) - Validates existence and current status, updates status to SUBMITTED
- [inventory::StockAdjustmentLine](../model/StockAdjustmentLine.md) - Reads adjustment lines to create normalized execution effects
- [inventory::InventoryExecution](../model/InventoryExecution.md) - Records the unposted stock adjustment execution and normalized stock effects for later confirmation

## Error Scenarios

- **STOCK_ADJUSTMENT_NOT_FOUND**: Referenced stock adjustment does not exist
- **INVALID_STATUS**: Target entity is not in a valid status for this operation

## Test Cases

- returns error when stock adjustment does not exist
- returns error when stock adjustment is not in DRAFT status
- transitions stock adjustment from DRAFT to SUBMITTED
- does not create inventory execution when line item validation fails
