aeat.domain.renta._ledger_expenses module¶
Renta deductible-expense observations derived from ledger facts.
RentaDeductibleExpenseFact is evaluated through
evaluate_renta_deductibility() using CategoryProfile and
RentaDeductibilityContext; eligible
RentaDeductibilityResult values become
RentaDeductibleExpenseObservation records routed through
RENTA_100_FIRST_SLICE_EXPENSE_CASILLAS to registry
CasillaId bindings for M100.
- class RentaExpenseDirection(*values)[source]¶
Bases:
StrEnumClosed direction values for first-slice Renta expense facts.
- OUTGOING_EXPENSE¶
- REFUND¶
- REVERSAL¶
- class RentaDeductibilityStatus(*values)[source]¶
Bases:
StrEnumWhether a ledger fact can produce a Renta calculation observation.
- ELIGIBLE¶
- INELIGIBLE¶
- class RentaInvoiceEvidenceStatus(*values)[source]¶
Bases:
StrEnumInvoice-evidence state carried by the Renta observation.
- NONE¶
- LINKED¶
- class RentaReconciliationStatus(*values)[source]¶
Bases:
StrEnumTransaction/invoice reconciliation state for duplicate prevention.
- TRANSACTION_ONLY¶
- LINKED_INVOICE¶
- class RentaDeductibilityContext(**data)[source]¶
Bases:
_RentaStrictFrozenModelInputs that affect proportionality but are not ledger facts.
- Parameters:
- profile_year: int¶
- usage_ratios: dict[SpendingCategory, Decimal]¶
- statutory_cap_days: Decimal | None¶
- statutory_cap_variant_id: str | None¶
- statutory_cap_person_count: int¶
- exclusive_use_confirmed: bool¶
- residence_ccaa: CCAA | None¶
Ordinary residence comunidad autonoma, sourced from
TaxResidenceProfile.ccaa.Optional and inert for the general expense path: LIRPF arts. 28-30 base-imponible deductibility is state law and does not vary by comunidad (Ley 22/2009 cesion framework grants no base competence to the CCAA). The axis only selects a territorial-regime override where one is declared for the fact’s category; when an override exists but this field is
Nonethe evaluation fails closed rather than silently choosing a base (seeselect_deductibility_profile()).
- class RentaDeductibleExpenseFact(**data)[source]¶
Bases:
_RentaStrictFrozenModelCanonical ledger fact eligible for Renta deductibility evaluation.
- Parameters:
transaction_id (str)
invoice_id (str | None)
catalogue_id (str)
operation_date (date)
invoice_issue_date (date | None)
posting_date (date | None)
payment_date (date | None)
gross_amount (Decimal)
taxable_base (Decimal | None)
iva_amount (Decimal | None)
currency (Literal['EUR'])
direction (RentaExpenseDirection)
category (SpendingCategory)
activity_key (str)
- transaction_id: str¶
- invoice_id: str | None¶
- catalogue_id: str¶
- operation_date: date¶
- invoice_issue_date: date | None¶
- posting_date: date | None¶
- payment_date: date | None¶
- gross_amount: Decimal¶
- taxable_base: Decimal | None¶
- iva_amount: Decimal | None¶
- currency: Literal['EUR']¶
- direction: RentaExpenseDirection¶
- category: SpendingCategory¶
- activity_key: str¶
- class RentaDeductibilityResult(**data)[source]¶
Bases:
_RentaStrictFrozenModelDeductibility evaluation result before registry binding resolution.
- Parameters:
transaction_id (str)
invoice_id (str | None)
category (SpendingCategory)
category_family (SpendingCategoryFamily)
profile_year (int)
proportionality_kind (ProportionalityKind)
status (RentaDeductibilityStatus)
reason (str)
gross_amount (Decimal)
deductible_amount (Decimal)
non_deductible_amount (Decimal)
applied_ratio (Decimal | None)
statutory_cap_applied (Decimal | None)
legal_references (tuple[CategoryCitation, ...])
- transaction_id: str¶
- invoice_id: str | None¶
- category: SpendingCategory¶
- category_family: SpendingCategoryFamily¶
- profile_year: int¶
- proportionality_kind: ProportionalityKind¶
- status: RentaDeductibilityStatus¶
- reason: str¶
- gross_amount: Decimal¶
- deductible_amount: Decimal¶
- non_deductible_amount: Decimal¶
- applied_ratio: Decimal | None¶
- statutory_cap_applied: Decimal | None¶
- legal_references: tuple[CategoryCitation, ...]¶
- class RentaDeductibleExpenseObservation(**data)[source]¶
Bases:
_RentaStrictFrozenModelBinding-ready Renta expense observation for the first Modelo 100 slice.
- Parameters:
observation_id (str)
source_kind (Literal['ledger_renta_expense_aggregation'])
modelo (Literal[Modelo.M100])
period (Literal['0A'])
tax_year (int)
activity_key (str)
target_casilla_id (CasillaId)
transaction_id (str)
invoice_id (str | None)
catalogue_id (str)
operation_date (date)
invoice_issue_date (date | None)
posting_date (date | None)
payment_date (date | None)
filing_date (date)
gross_amount (Decimal)
taxable_base (Decimal | None)
iva_amount (Decimal | None)
deductible_amount (Decimal)
non_deductible_amount (Decimal)
currency (Literal['EUR'])
direction (RentaExpenseDirection)
sign (Literal[-1, 1])
category (SpendingCategory)
category_family (SpendingCategoryFamily)
profile_year (int)
proportionality_kind (ProportionalityKind)
applied_ratio (Decimal | None)
invoice_evidence_status (RentaInvoiceEvidenceStatus)
reconciliation_status (RentaReconciliationStatus)
legal_references (tuple[CategoryCitation, ...])
- observation_id: str¶
- source_kind: Literal['ledger_renta_expense_aggregation']¶
- modelo: Literal[Modelo.M100]¶
- period: Literal['0A']¶
- tax_year: int¶
- activity_key: str¶
- target_casilla_id: CasillaId¶
- transaction_id: str¶
- invoice_id: str | None¶
- catalogue_id: str¶
- operation_date: date¶
- invoice_issue_date: date | None¶
- posting_date: date | None¶
- payment_date: date | None¶
- filing_date: date¶
- gross_amount: Decimal¶
- taxable_base: Decimal | None¶
- iva_amount: Decimal | None¶
- deductible_amount: Decimal¶
- non_deductible_amount: Decimal¶
- currency: Literal['EUR']¶
- direction: RentaExpenseDirection¶
- sign: Literal[-1, 1]¶
- category: SpendingCategory¶
- category_family: SpendingCategoryFamily¶
- profile_year: int¶
- proportionality_kind: ProportionalityKind¶
- applied_ratio: Decimal | None¶
- invoice_evidence_status: RentaInvoiceEvidenceStatus¶
- reconciliation_status: RentaReconciliationStatus¶
- legal_references: tuple[CategoryCitation, ...]¶
- normalize_spending_category(value)[source]¶
Normalize persisted category identifiers to closed enum members.
- Return type:
- Returns:
The
SpendingCategorymember for the given value.- Parameters:
value (SpendingCategory | str)
- resolve_region_category_profiles(profile_year)[source]¶
Return the territorial-regime category-profile overrides for a filing year.
The override layer is provisioned but deliberately empty: the only genuinely region-varying expense-side regimes reach the base through their own dedicated bindings (the Reserva para Inversiones en Canarias, Ley 19/1994 art. 27, is modelled as its own binding, not a
SpendingCategoryprofile), and the Ceuta/Melilla benefit is an art. 68.4 cuota deduction rather than a base-imponible expense rule. NoSpendingCategorytherefore warrants a per-comunidad deductibility variant today, so this resolver returns an empty mapping and every fact falls through to the state year profile. A future territorial-regime enrollment populates this mapping (grounded to its regime law) with no further architectural change.- Return type:
- Returns:
Mapping from
CCAAto a per-SpendingCategoryoverride profile mapping; empty until a territorial regime is enrolled.- Parameters:
profile_year (int)
- select_deductibility_profile(*, state_profile, region_override_profiles, context)[source]¶
Select the applicable category profile, honouring territorial-regime overrides.
region_override_profilesholds the per-CCAAoverrides declared for the fact’s category (empty for the general state-law case). Selection:no override for the category: return
state_profileunchanged (general expense deductibility is state base-imponible law, invariant across comunidades);the category carries an override but
context.residence_ccaa is None: returnNone(D4 fail-closed) so the caller refuses rather than silently choosing a base for an undeclared region;the residence comunidad has an override: return that override profile;
the residence comunidad has no override (a different comunidad owns the regime): return
state_profile(state law applies to this taxpayer’s region).
- Return type:
- Returns:
The selected
CategoryProfile, orNonewhen a region override exists for the category but the residence comunidad is undeclared.- Parameters:
state_profile (CategoryProfile)
region_override_profiles (Mapping[CCAA, CategoryProfile])
context (RentaDeductibilityContext)
- evaluate_renta_deductibility(fact, profile, context)[source]¶
Evaluate one classified ledger fact and return a
RentaDeductibilityResult.- Return type:
- Parameters:
fact (RentaDeductibleExpenseFact)
profile (CategoryProfile)
context (RentaDeductibilityContext)
- build_renta_deductible_expense_observation(fact, result, *, tax_year)[source]¶
Build a first-slice Modelo 100 observation from an eligible result.
- Return type:
- Returns:
A
RentaDeductibleExpenseObservationready for filing assembly.- Parameters:
fact (RentaDeductibleExpenseFact)
result (RentaDeductibilityResult)
tax_year (int)