aeat.application.aggregation._renta_ledger module¶
Repository-backed Modelo 100 Renta expense aggregation.
This is the annual first-slice expense projection behind the
ledger_renta_expense_aggregation source. It loads both a
TransactionCatalogue and a
InvoiceCatalogue from the active bucket through
TransactionCatalogueRepository and
InvoiceCatalogueRepository, uses
purchase-invoice evidence to validate deductible-expense facts, and returns
binding-ready RentaDeductibleExpenseObservation
records.
The source-mesh resolver in _modelo_bindings applies the target
ModeloRevision, resolves registry
bindings, and reports source issues or unrouted expenses on its
CalculationSourceResolution. The M130 quarterly gasto
projection is intentionally separate in _renta_gasto_ledger.
Related: _iva_ledger and _renta_income_ledger for sibling
ledger projections.
- class RentaLedgerAggregationIssueReason(*values)[source]¶
Bases:
StrEnumMachine-readable reasons why a ledger row did not produce an observation.
The five upstream filter rejections (
UNSUPPORTED_DIRECTION,UNSUPPORTED_CURRENCY,UNCLASSIFIED_BUSINESS_STATE,PERSONAL_TRANSACTION,OUTSIDE_PERIOD) are shared withIvaLedgerAggregationIssueReasonthrough_shared_issue_reasons.UNSUPPORTED_PERIODis a Renta-only refusal raised against quarter-level requests; the remaining values describe Renta-specific deductibility checks.- UNSUPPORTED_PERIOD¶
- UNSUPPORTED_DIRECTION¶
- UNSUPPORTED_CURRENCY¶
- UNCLASSIFIED_BUSINESS_STATE¶
- PERSONAL_TRANSACTION¶
- MISSING_CATEGORY¶
- UNKNOWN_CATEGORY¶
- CATEGORY_OUTSIDE_FIRST_SLICE¶
- MISSING_CATEGORY_PROFILE¶
- OUTSIDE_PERIOD¶
- MISSING_PURCHASE_INVOICE_EVIDENCE¶
- UNSUPPORTED_PURCHASE_INVOICE_EVIDENCE_KIND¶
- PURCHASE_INVOICE_EVIDENCE_BUCKET_MISMATCH¶
- PURCHASE_INVOICE_EVIDENCE_LINK_MISMATCH¶
- PARTIAL_OR_MULTI_TRANSACTION_PURCHASE_INVOICE_EVIDENCE¶
- AMOUNT_MISMATCH¶
- INVALID_LEDGER_FACT¶
- INELIGIBLE_DEDUCTIBILITY¶
- REGION_UNDECLARED_FOR_OVERRIDE¶
- class RentaLedgerAggregationIssue(**data)[source]¶
Bases:
BaseModelTraceable exclusion emitted while aggregating ledger rows.
- Parameters:
transaction_id (str)
purchase_invoice_evidence_id (str | None)
category_id (str | None)
reason (RentaLedgerAggregationIssueReason)
detail (str)
- transaction_id: str¶
- purchase_invoice_evidence_id: str | None¶
- category_id: str | None¶
- reason: RentaLedgerAggregationIssueReason¶
- detail: str¶
- class RentaLedgerExpenseAggregation(**data)[source]¶
Bases:
BaseModelFirst-slice Renta observations plus binding-ready casilla totals.
- Parameters:
modelo (str)
period (Period)
profile_year (int)
observations (Sequence[RentaDeductibleExpenseObservation])
issues (Sequence[RentaLedgerAggregationIssue])
casilla_aggregation (CasillaAggregation)
- modelo: str¶
- period: Period¶
- profile_year: int¶
- observations: Sequence[RentaDeductibleExpenseObservation]¶
- issues: Sequence[RentaLedgerAggregationIssue]¶
- casilla_aggregation: CasillaAggregation¶
- aggregate_renta_ledger_expenses_from_repositories(*, bucket_id, period, transaction_repository=None, invoice_repository=None, profile_year=None, usage_ratios=None, activity_key='default', modelo='100', profile_record=None, region_category_overrides=None)[source]¶
Load persisted catalogues and aggregate first-slice Renta expenses.
Derives the ordinary-residence comunidad autonoma from the bucket’s active profile (
tax_residence.ccaa) and threads it into the aggregation so a territorial-regime deductibility override selects by residence; the axis is fail-closed (an undeclared or unparseable region resolves to the state year profile) and byte-identical while the override layer is empty. Passprofile_recordto supply theUserProfileRecorddirectly (the residence is otherwise loaded from the bucket), andregion_category_overridesto supply the per-CCAAoverride layer forwarded toaggregate_renta_ledger_expenses()(defaulting to the empty registry-provisioned layer,resolve_region_category_profiles()).Returns a
RentaLedgerExpenseAggregation.- Return type:
- Parameters:
bucket_id (str)
period (Period)
transaction_repository (TransactionCatalogueRepositoryProtocol | None)
invoice_repository (InvoiceCatalogueRepositoryProtocol | None)
profile_year (int | None)
usage_ratios (Mapping[SpendingCategory, Decimal] | None)
activity_key (str)
modelo (str)
profile_record (UserProfileRecord | None)
region_category_overrides (Mapping[CCAA, Mapping[SpendingCategory, CategoryProfile]] | None)
- aggregate_renta_ledger_expenses(transactions, invoices, *, bucket_id, period, profile_year=None, usage_ratios=None, activity_key='default', modelo='100', residence_ccaa=None, region_category_overrides=None)[source]¶
Aggregate classified ledger transactions into Renta expense observations.
- Parameters:
transactions (
TransactionCatalogue) – TheTransactionCataloguesupplying active ledger entries.invoices (
InvoiceCatalogue) – TheInvoiceCatalogueused for invoice-linked deductibility checks.bucket_id (
str) – Activity bucket identifier for scoping the aggregation.profile_year (
int|None) – Optional category-profile year override; defaults to theperiod.yearwhenNone.usage_ratios (
Mapping[SpendingCategory,Decimal] |None) – Optional per-SpendingCategorybusiness-use ratio overrides applied before deductibility calculation.activity_key (
str) – Activity identifier carried through to the produced observations’ provenance; defaults to"default".modelo (
str) – Modelo identifier ("100"IRPF or"130"pagos fraccionados) selecting the per-modelo deductibility rules.residence_ccaa (
CCAA|None) – Optional ordinary residence comunidad autonoma, used only to select a territorial-regime deductibility override; inert while the override layer is empty and general expense deductibility is state law.region_category_overrides (
Mapping[CCAA,Mapping[SpendingCategory,CategoryProfile]] |None) – Optional per-CCAAcategory-profile override layer; defaults toresolve_region_category_profiles()(empty) so every fact falls through to the state year profile.
- Return type:
Returns a
RentaLedgerExpenseAggregationcontaining the accepted observations, exclusion issues, and binding-ready casilla totals.