# UpdateStockMovement

## Permission Scope

stockOperation

## Overview

updateStockMovement modifies a stock movement that is still in DRAFT status. Fields can be updated and move lines can be added or removed. The same validation rules from creation apply to any changed fields.

## Business Rules

- Stock movement must exist
- Stock movement must be in DRAFT status
- Same validation rules as creation apply to changed fields and new lines

## Process Flow

```mermaid
flowchart TD
    A[Receive update request] --> B{Movement exists?}
    B -->|No| C[Return error: STOCK_MOVEMENT_NOT_FOUND]
    B -->|Yes| D{Status is DRAFT?}
    D -->|No| E[Return error: STOCK_MOVEMENT_NOT_DRAFT]
    D -->|Yes| F[Apply changes and validate]
    F --> G[Update movement record]
    G --> H[Return updated movement]
```

## External Dependencies

- None

## Error Scenarios

- **STOCK_MOVEMENT_NOT_FOUND**: Referenced stock movement does not exist
- **STOCK_MOVEMENT_NOT_DRAFT**: Stock movement is not in DRAFT status

## Test Cases

- returns error when not found
- returns error when not in DRAFT
- returns error when line item not active
- returns error when line quantity is zero or negative
- returns error when source equals destination
- returns error when location not found
- updates movement date
- adds new move line
- removes move line
