# DeactivateRouting

## Permission Scope

manufacturingMaster

## Overview

DeactivateRouting removes an active routing from future production-order selection. Released production orders keep their frozen operation plan even after the routing is deactivated.

## Business Rules

- Target routing must exist.
- Only `ACTIVE` routings can be deactivated.
- Deactivation blocks future selection for release.
- Existing production-order and work-order snapshots remain valid.
- Deactivation may be blocked when future scheduling policy requires a replacement routing first.

## Process Flow

```mermaid
flowchart TD
    A[Receive deactivate request] --> B{Routing exists?}
    B -->|No| C[Return ROUTING_NOT_FOUND]
    B -->|Yes| D{Status is ACTIVE?}
    D -->|No| E[Return ROUTING_NOT_DEACTIVATABLE]
    D -->|Yes| F{Replacement policy satisfied?}
    F -->|No| G[Return REPLACEMENT_REQUIRED]
    F -->|Yes| H[Set status to INACTIVE]
    H --> I[Return inactive routing]
```

## External Dependencies

- None

## Error Scenarios

- **ROUTING_NOT_FOUND**: Referenced routing does not exist
- **ROUTING_NOT_DEACTIVATABLE**: The routing is not in `ACTIVE`.
- **REPLACEMENT_REQUIRED**: Policy requires another selectable BOM or routing before deactivation

## Test Cases

- deactivates an active routing
- returns error when the routing does not exist
- returns error when the routing is not active
- returns error when replacement policy blocks deactivation
- preserves released operation snapshots after deactivation
