# CancelStockAdjustment

## Permission Scope

inventoryControl

## Overview

cancelStockAdjustment transitions a stock adjustment from DRAFT to CANCELLED status. This allows users to discard an adjustment that was created in error or is no longer needed before it enters the approval workflow. Only adjustments in DRAFT status can be cancelled. No inventory or ledger changes occur.

## Business Rules

- Stock adjustment must exist
- Stock adjustment must be in DRAFT status
- Transitions status from DRAFT to CANCELLED
- No inventory or ledger changes occur

## Process Flow

```mermaid
flowchart TD
    A[Cancel 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[Transition to CANCELLED]
    F --> G[Return updated stock adjustment]
```

## External Dependencies

- [inventory::StockAdjustment](../models/StockAdjustment.md) - Validates existence and current status, updates status to CANCELLED

## 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
- returns error when already cancelled
- transitions stock adjustment from DRAFT to CANCELLED
