aeat.domain.fincas._expense_rollup module¶
LIRPF art. 23.1 expense rollup with art. 23.1.a) cap.
compute_gastos_for_year() aggregates per-finca
FincaGasto rows into a GastosForYear result by
ExpenseCategory. It implements the art. 23.1.a) párrafo segundo cap:
intereses de los capitales ajenos (FINANCIACION_INTERESES) plus gastos de
conservación y reparación (CONSERVACION_REPARACION) jointly capped at the
ingresos íntegros del arrendamiento for the same period; the excess carries
forward up to 4 years and is consumed against future ingresos for the same
finca.
Carry-forward representation: a per-finca FIFO queue of
CarryForwardEntry rows keyed by origination year. Each entry records the
original-year and the remaining unconsumed amount. Entries older than 4 years are
dropped at rollup time per BOE: “El exceso … se podrá deducir en los cuatro
años siguientes”.
- CARRY_FORWARD_MAX_YEARS: int¶
en los cuatro años siguientes.- Type:
LIRPF art. 23.1.a) párrafo segundo
- CAPPED_CATEGORIES: frozenset[ExpenseCategory]¶
The two categories subject to the joint art. 23.1.a) cap.
- class CarryForwardEntry(**data)[source]¶
Bases:
BaseModelA single carry-forward generation, anchored to its origination year.
- origination_year: int¶
- remaining_amount: Decimal¶
- class GastosForYear(**data)[source]¶
Bases:
BaseModelAggregated per-finca gastos for a single ejercicio.
- Variables:
period_year – Ejercicio.
ingresos_for_period – Sum of gross_rent_received across the finca’s contracts for the period.
por_categoria – Sum per
ExpenseCategory(uncapped).capped_categories_subtotal – Sum of capped-category expenses for the period (FINANCIACION + CONSERVACION).
capped_categories_applied – Capped subtotal after the art. 23.1.a) cap is applied (= min(subtotal + consumed_carry, ingresos_for_period)).
capped_categories_excess – Capped subtotal that COULD NOT be consumed in the period after applying the cap.
carry_consumed – Carry-forward consumed (fed into capped_categories_applied).
carry_forward_after – Carry-forward queue after the rollup (post-FIFO consumption + 4-year expiration).
total_deductible – Sum across all deductible categories after applying caps and carry-forward consumption.
- Parameters:
period_year (int)
ingresos_for_period (Decimal)
por_categoria (dict[ExpenseCategory, Decimal])
capped_categories_subtotal (Decimal)
capped_categories_applied (Decimal)
capped_categories_excess (Decimal)
carry_consumed (Decimal)
carry_forward_after (tuple[CarryForwardEntry, ...])
total_deductible (Decimal)
- period_year: int¶
- ingresos_for_period: Decimal¶
- por_categoria: dict[ExpenseCategory, Decimal]¶
- capped_categories_subtotal: Decimal¶
- capped_categories_applied: Decimal¶
- capped_categories_excess: Decimal¶
- carry_consumed: Decimal¶
- carry_forward_after: tuple[CarryForwardEntry, ...]¶
- total_deductible: Decimal¶
- compute_gastos_for_year(expenses, *, period_year, ingresos_for_period, carry_forward_in=())[source]¶
Roll up per-finca gastos for
period_year.- Parameters:
expenses (
Iterable[FincaGasto]) – Expense rows for the target finca + period.period_year (
int) – Ejercicio.ingresos_for_period (
Decimal) – Gross-rent sum across the finca’s contracts forperiod_year. Drives the art. 23.1.a) cap.carry_forward_in (
Sequence[CarryForwardEntry]) – Pre-existing carry-forward queue from prior rollups for the same finca. Entries older thanCARRY_FORWARD_MAX_YEARSfromperiod_yearare dropped.
- Return type:
- Returns:
GastosForYearcarrying the aggregated rollup, the cap outcome, and the post-rollup carry-forward queue.