# SupplierAccount

## Description

SupplierAccount represents the supplier-facing transaction unit for one BusinessPartner in one Company. It separates company-specific procurement and payment settings from the global identity and allows multiple procurement units for the same partner.

## Domain Model Definitions

### Model type

Stateful

#### State Transitions

```mermaid
stateDiagram-v2
    [*] --> Active: createSupplierAccount (status=ACTIVE)
    Active --> Inactive: deactivateSupplierAccount
    Inactive --> Active: reactivateSupplierAccount
```

| Operation | From | To | Command |
|-----------|------|----|---------|
| deactivate | ACTIVE | INACTIVE | [deactivateSupplierAccount](../command/DeactivateSupplierAccount.md) |
| reactivate | INACTIVE | ACTIVE | [reactivateSupplierAccount](../command/ReactivateSupplierAccount.md) |

### Command Definitions

- [createSupplierAccount](../command/CreateSupplierAccount.md) - Create an active supplier account and its initial usages
- [updateSupplierAccount](../command/UpdateSupplierAccount.md) - Patch mutable account fields and apply line-style usage changes
- [deactivateSupplierAccount](../command/DeactivateSupplierAccount.md) - Stop the account without affecting the global partner
- [reactivateSupplierAccount](../command/ReactivateSupplierAccount.md) - Restore an inactive account for business use

### Query Definitions

- [GetSupplierAccount](../query/GetSupplierAccount.md) - Retrieve an account by id

### Models

- SupplierAccount
- SupplierAddressUsage
- SupplierBankAccountUsage

### Invariants

- Account name is required and must not be empty or whitespace-only

- The partner must be ACTIVE when an account is created
- Account code is required and unique within a company
- Company, preferred currency, and default expense account references must exist
- The optional default expense account belongs to the same company, is active, and has type `EXPENSE`
- Address and bank account usages may only reference records owned by the same partner
- At most one default exists per usage purpose within an account
- Accounts are active when created
- SupplierAccount records are deactivated rather than physically deleted
- Only active accounts are available for new supplier transactions
- Approval or registration workflow, if required, is modeled separately from SupplierAccount
- Account deactivation is independent from BusinessPartner availability

### Relationships

- **References BusinessPartner**: Identity and globally maintained master data
- **References Company**: Organizational scope of the transaction account
- **References Currency**: Optional preferred transaction currency
- **References Account**: Optional default expense account for non-PO supplier invoices
- **Referenced By SupplierAddressUsage**: Purpose-specific address configuration
- **Referenced By SupplierBankAccountUsage**: Purpose-specific bank configuration
