Source code for aeat.application.aggregation._currency_predicates
"""Shared currency predicates for aggregation gates.Used by :mod:`~._iva_ledger`, :mod:`~._renta_ledger`,:mod:`~._renta_income_ledger`, and :mod:`~._renta_gasto_ledger` to gatenon-EUR rows and extract effective EUR amounts.Provides two predicates that replace independent``if transaction.raw.currency != "EUR": ...`` guards."""from__future__importannotationsfromdecimalimportDecimalfrom...core.external_constantsimportDEFAULT_CURRENCYfrom...domain.transactionsimportTransaction
[docs]defis_non_eur_without_conversion(transaction:Transaction)->bool:"""Return whether a transaction is foreign-currency with no pre-converted EUR value. Returns ``True`` only when both conditions hold: - the raw currency is not EUR, AND - ``value_in_eur`` is ``None`` (no conversion was applied at import). Aggregation gates use this predicate to decide whether to emit ``UNSUPPORTED_CURRENCY``. A non-EUR row with ``value_in_eur`` set can proceed through the gate using the pre-converted amount. Args: transaction: The transaction to inspect. Returns: ``True`` if the currency is foreign and no EUR equivalent is available. """returntransaction.raw.currency!=DEFAULT_CURRENCYandtransaction.value_in_eurisNone
[docs]defeffective_eur_amount(transaction:Transaction)->Decimal:"""Return the EUR amount to use for this transaction in casilla projections. Returns ``transaction.value_in_eur`` for foreign-currency rows whose conversion was pre-applied at import; otherwise returns ``transaction.raw.amount`` (the native EUR amount for domestic rows). Note: callers are responsible for ensuring ``is_non_eur_without_conversion`` returns ``False`` before calling this function. An unconverted foreign-currency row would return ``raw.amount`` in a foreign currency, which is not a valid EUR projection. Args: transaction: The transaction whose effective EUR amount is needed. Returns: A :class:`decimal.Decimal` suitable for casilla arithmetic. """iftransaction.value_in_eurisnotNone:returntransaction.value_in_eurreturntransaction.raw.amount