# ReleaseReservation

## Permission Scope

stockOperation

## Overview

releaseReservation releases a previously reserved quantity of stock, restoring it to available status. This is used when a reservation is no longer needed, such as when a sales order is cancelled or fulfilled through a different mechanism.

## Business Rules

- A stock level record must exist for the item-location pair
- The current reserved quantity must be sufficient for the release amount

## Process Flow

```mermaid
flowchart TD
    A[Receive release request] --> B{Stock level exists?}
    B -->|No| C[Return error: STOCK_LEVEL_NOT_FOUND]
    B -->|Yes| D{Reserved >= release amount?}
    D -->|No| E[Return error: INSUFFICIENT_RESERVED_STOCK]
    D -->|Yes| F[Decrease reserved quantity]
    F --> G[Return updated stock level]
```

## External Dependencies

- None

## Error Scenarios

- **STOCK_LEVEL_NOT_FOUND**: No stock level record exists for the item-location pair
- **INSUFFICIENT_RESERVED_STOCK**: Release amount exceeds the currently reserved quantity

## Test Cases

- returns error when stock level not found
- returns error when release exceeds reserved
- releases reservation successfully
