# UpdateInvoiceToleranceConfig

## Permission Scope

accountPayableDocument

## Overview

updateInvoiceToleranceConfig updates an existing supplier-specific invoice tolerance configuration. Callers can set individual tolerance fields to null to fall back to strict matching for that field.

## Business Rules

- The invoice tolerance config must exist
- The target config is identified by companyId and supplierAccountId
- Tolerance fields are updated through patch
- Tolerance values must be non-negative when provided
- Undefined fields are left unchanged
- Null tolerance fields clear the supplier override for that tolerance field

## Process Flow

```mermaid
flowchart TD
    A[Receive update invoice tolerance config request] --> B{Config exists?}
    B -->|No| C[Return error: INVOICE_TOLERANCE_CONFIG_NOT_FOUND]
    B -->|Yes| D{Tolerance values valid?}
    D -->|No| E[Return error: INVALID_TOLERANCE_VALUE]
    D -->|Yes| F[Update invoice tolerance config]
    F --> G[Return updated invoice tolerance config]
```

## External Dependencies

- None

## Error Scenarios

- **INVOICE_TOLERANCE_CONFIG_NOT_FOUND**: Referenced invoice tolerance config does not exist
- **INVALID_TOLERANCE_VALUE**: Invoice tolerance value must not be negative

## Test Cases

- updates invoice tolerance config
- clears invoice tolerance config fields with null
- returns the existing config when no fields are changed
- returns error when config does not exist
- returns error when tolerance value is negative
