aeat.application.aggregation._renta_income_ledger module

Repository-backed Renta actividad-income aggregation.

This is the ledger projection behind the ledger_renta_income_aggregation source for Modelo 130 and Modelo 100. The quarterly entry point aggregate_renta_income_ledger_from_repositories() loads a TransactionCatalogue via TransactionCatalogueRepository from the active bucket and delegates to aggregate_renta_income_ledger() for period-scoped aggregation.

Modelo 130 casilla 01 (Ingresos íntegros) accumulates professional-service revenue from the start of the fiscal year through the end of the declared quarter. Unlike the expense pipeline, which processes annual periods, the income pipeline accepts a quarterly period token and applies a cumulative year-to-date window.

Cumulative window rule (RD 439/2007 art. 110.2):

For period Qn in year Y the window is [Jan 1, Y] through [last day of Qn, Y]. Q1 covers Jan-Mar; Q2 covers Jan-Jun; Q3 covers Jan-Sep; Q4 covers Jan-Dec.

Only ACTIVE, EUR-denominated, INCOMING transactions whose business_classification is BUSINESS or MIXED are eligible. Transactions whose value_date (or booked_date if absent) falls outside the cumulative window are excluded with a traceable issue record.

Modelo 100 uses the annual counterpart aggregate_renta_m100_income_ledger(), which keeps the same activity-income eligibility rules but targets the annual IRPF income leaf. The source-mesh resolver in _modelo_bindings chooses the correct path for the requested modelo and returns the binding values as a CalculationSourceResolution.

class RentaIncomeLedgerAggregationIssueReason(*values)[source]

Bases: StrEnum

Machine-readable reasons why a ledger row did not produce an income observation.

UNSUPPORTED_DIRECTION
UNSUPPORTED_CURRENCY
UNCLASSIFIED_BUSINESS_STATE
PERSONAL_TRANSACTION
OUTSIDE_PERIOD
UNSUPPORTED_PERIOD
TRABAJO_INCOME
class RentaIncomeLedgerAggregationIssue(**data)[source]

Bases: BaseModel

Traceable exclusion emitted while aggregating income ledger rows.

Parameters:
transaction_id: str
reason: RentaIncomeLedgerAggregationIssueReason
detail: str
class RentaIncomeObservation(**data)[source]

Bases: BaseModel

One eligible INCOMING professional-income ledger row.

Carries the typed gross amount and the target casilla id it feeds. The domain registry resolver matches target_casilla_id against the binding selector and sums gross_amount (or taxable_base_amount) across all observations for that casilla depending on the declared fact.

taxable_base_amount is the IVA-exclusive base imponible from the original invoice (transaction.taxable_base). It feeds the taxable_base_sum fact path used by the rendimiento-neto binding (casilla 03). None when the transaction carries no explicit taxable_base.

source_jurisdiction propagates the per-transaction ISO 3166-1 alpha-2 source-jurisdiction provenance from the originating ledger row. LIRPF Art. 8 establishes the universal-base presumption for Spanish residents, so M130 / M100 aggregate ALL source jurisdictions into the same base — the field is preserved for audit and for downstream IRNR / Beckham engines that read foreign-source rows.

Parameters:
  • transaction_id (str)

  • target_casilla_id (CasillaId)

  • gross_amount (Decimal)

  • taxable_base_amount (Decimal | None)

  • withheld_amount (Decimal)

  • filing_date (date)

  • source_jurisdiction (str | None)

transaction_id: str
target_casilla_id: CasillaId
gross_amount: Decimal
taxable_base_amount: Decimal | None
withheld_amount: Decimal
filing_date: date
source_jurisdiction: str | None
class RentaIncomeLedgerAggregation(**data)[source]

Bases: BaseModel

Cumulative income observations for one M130 quarter window.

out_of_window_summary is populated by repository-backed date partitions. Full-catalogue aggregation keeps row-level issues because every transaction is already loaded for classification.

Parameters:
modelo: str
period: Period
observations: Sequence[RentaIncomeObservation]
issues: Sequence[RentaIncomeLedgerAggregationIssue]
out_of_window_summary: OutOfWindowTransactionSummary | None
casilla_aggregation: CasillaAggregation
aggregate_renta_income_ledger_from_repositories(*, bucket_id, period, transaction_repository=None)[source]

Load the transaction catalogue and aggregate cumulative M130 income.

Returns a RentaIncomeLedgerAggregation.

Return type:

RentaIncomeLedgerAggregation

Parameters:
aggregate_renta_income_ledger(transactions, *, bucket_id, period)[source]

Aggregate INCOMING professional-income transactions into M130 casilla 01.

Parameters:
  • transactions (TransactionCatalogue) – The TransactionCatalogue of ledger transactions to aggregate.

  • bucket_id (str) – Bucket identifier carried through to provenance and audit records so the resulting aggregation cannot be silently misattributed.

  • period (Period) – The quarterly Period whose year anchors the cumulative window.

Return type:

RentaIncomeLedgerAggregation

Returns a RentaIncomeLedgerAggregation covering the cumulative fiscal window. period must be quarterly. The cumulative window extends from Jan 1 of the period’s year through the last day of the declared quarter, implementing the year-to-date accumulation rule for IRPF pagos fraccionados (RD 439/2007 art. 110.2).

aggregate_renta_m100_income_ledger_from_repositories(*, bucket_id, period, transaction_repository=None)[source]

Load the catalogue and aggregate the annual Modelo 100 actividad income.

Return type:

RentaIncomeLedgerAggregation

Returns:

The RentaIncomeLedgerAggregation for the requested annual period.

Parameters:
aggregate_renta_m100_income_ledger(transactions, *, bucket_id, period)[source]

Aggregate annual actividad-económica income from a TransactionCatalogue into Modelo 100 casilla 0171.

The annual counterpart of aggregate_renta_income_ledger(): it applies the same actividad-económica eligibility (excluding nómina/trabajo and personal flows) over the FULL ejercicio (Jan 1 to Dec 31 of period.year) and targets the M100 “Ingresos de explotación” leaf (0171) instead of the M130 cumulative casilla. period must be the annual period.

Return type:

RentaIncomeLedgerAggregation

Returns:

The RentaIncomeLedgerAggregation built from eligible transactions.

Parameters: