aeat.domain.currency._service module

Currency normalization service: convert foreign amounts to EUR.

Provides ExchangeRateProvider — the protocol an exchange-rate backend must implement — and CurrencyNormalizationService, which applies a provider-supplied rate to produce a NormalizedAmount (from ._models). When no provider is configured or no rate is available the service returns a NormalizedAmount with status = CurrencyNormalizationStatus.MISSING_RATE so callers can surface a human-readable warning rather than silently propagating a zero amount into a filing (modelo = an AEAT tax form).

class ExchangeRateProvider(*args, **kwargs)[source]

Bases: Protocol

Protocol for fetching exchange rates.

get_eur_rate(currency, rate_date)[source]

Get the exchange rate to EUR for a given currency and date.

Returns the rate such that original_amount * rate = eur_amount. Returns None if no rate is available.

Return type:

Decimal | None

Parameters:
class CurrencyNormalizationService(rate_provider=None)[source]

Bases: object

Service to normalize foreign currencies to EUR.

Parameters:

rate_provider (ExchangeRateProvider | None)

normalize(amount, rate_date)[source]

Normalize an amount to EUR using the rate for the given date.

Return type:

NormalizedAmount

Returns:

A NormalizedAmount with the EUR-equivalent and conversion metadata.

Parameters: