# 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, or valuation changes occur at this stage. The StockAdjustment itself is the draft document; no separate execution document is created. Once submitted, the adjustment lines are frozen and can no longer be modified.

## Business Rules

- Stock adjustment must exist
- Stock adjustment must be in DRAFT status
- Validates that each StockAdjustmentLine references a valid item before transitioning
- Transitions status from DRAFT to SUBMITTED
- No execution document is created; the StockAdjustment itself is the draft document
- No stock, ledger, 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[Validate adjustment line items]
    F --> 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 validate line items before submission

## 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 update the adjustment when line item validation fails
