cadrumo.domain.calculations.registry.ledger_renta_income_bindings module¶
Canonical Renta income ledger aggregation binding family.
- validate_ledger_renta_income_aggregation_binding_definition(binding)[source]¶
Validate a
ledger_renta_income_aggregationbinding definition.- Return type:
- Parameters:
binding (BindingDefinition)
- class RentaIncomeObservationProtocol(*args, **kwargs)[source]¶
Bases:
ProtocolStructural protocol for actividad-económica income observations.
The registry only needs these attributes to resolve
ledger_renta_income_aggregationbindings; the fullRentaIncomeObservationsatisfies this protocol without any explicit declaration.- property transaction_id: str¶
Return the ledger row this observation was projected from.
Declared because a consumer samples these ids to name the offending rows in an ungrounded-income diagnostic. Leaving it off the protocol let a conforming implementation omit it and fail there at runtime.
- property target_casilla_id: CasillaId¶
Return the declaration casilla receiving the income aggregate.
- property taxable_base_amount: Decimal | None¶
Return the declared IVA-exclusive taxable base, when available.
- property grounding: LedgerIncomeGrounding¶
Return the substrate-grounding marker for the income observation.
- resolve_ledger_renta_income_aggregation_binding_values(revision, observations)[source]¶
Resolve every
ledger_renta_income_aggregationbinding onrevision.The
factdeclared in the binding selector controls which field is summed:"ingresos_integros_sum"→observation.taxable_base_amountwhen declared, elseobservation.gross_amount(per-observation fallback);"cash_received_sum"→observation.gross_amount;"taxable_base_sum"→observation.taxable_base_amount(a base-less row contributes nothing);"withheld_amount_sum"→observation.withheld_amount. Delegates the filter/aggregate skeleton toresolve_ledger_family_binding_values(), shared by every ledger family resolver.- Parameters:
revision (
ModeloRevision) – TheModeloRevisionwhose bindings are resolved.observations (
Iterable[RentaIncomeObservationProtocol]) – Renta income ledger lines to aggregate over.
- Return type:
- unsupported_ledger_renta_income_observations(revision, observations)[source]¶
Return the
RentaIncomeObservationProtocolrows no binding onrevisioncan consume.Delegates the screen to
unsupported_ledger_family_observations()— see that function for the shared fail-closed contract (why an unmatched observation is a modelling gap, not a legitimate zero). This family’s own contribution is narrow: thetarget_casilla_idmatch predicate (reused from the resolver’s_renta_income_build_matcher) and a false-fire guard that excludes an observation whose declarable amount —max(gross_amount, taxable_base_amount)when a base is declared,gross_amountotherwise — is zero. Noextra_exclusion.- Parameters:
revision (
ModeloRevision) – TheModeloRevisionwhose renta-income bindings define the supportedtarget_casilla_idset.observations (
Iterable[RentaIncomeObservationProtocol]) – Actividad-económica income observations to screen.
- Return type:
- Returns:
Tuple of observations whose non-zero income is selected by no
ledger_renta_income_aggregationbinding.
- class UngroundedRentaIncome(facts, observations)[source]¶
Bases:
NamedTupleBase-less income rows that a base-reading binding still consumes.
factsis the set of base-reading facts the revision actually declares, so a caller can describe the consequence precisely rather than guessing:ingresos_integros_summeans the listed rows contributed bank cash in place of a base,taxable_base_summeans they contributed nothing.observationsare the contributing rows, in input order.Empty
observationsmeans every consumed row declared its substrate; emptyfactsmeans the revision declares no base-reading income binding, in which caseobservationsis empty too.- Parameters:
observations (tuple[RentaIncomeObservationProtocol, ...])
-
observations:
tuple[RentaIncomeObservationProtocol,...]¶ Alias for field number 1
- ungrounded_ledger_renta_income_observations(revision, observations)[source]¶
Return the base-less rows a base-reading income binding on
revisionconsumes.The companion to
unsupported_ledger_renta_income_observations(), for the opposite failure: that screen catches a row NO binding consumes, this one catches a row a binding DOES consume but without the substrate the binding’s fact assumes. Both areno-silent-under-declarationscreens; neither changes a value.A row reaches an income casilla through declared substrate or through the cash fallback, and only the row’s
LedgerIncomeGroundingmarker distinguishes them — this screen keys on that marker, never ontaxable_base_amount is None, so the grounding fact has exactly one definition. Rows are screened against thetarget_casilla_idof the base-reading bindings only, so a revision whose income bindings all read cash or withholdings reports nothing.The caller surfaces the result as a NON-BLOCKING advisory: the fallback is deliberately kept (dropping an untagged income row would under-declare by the whole row, strictly worse than mis-measuring it), so what this screen buys is visibility, not exclusion.
- Parameters:
revision (
ModeloRevision) – TheModeloRevisionwhose renta-income bindings decide which casillas and facts are in play.observations (
Iterable[RentaIncomeObservationProtocol]) – Actividad-económica income observations to screen.
- Return type:
- Returns:
An
UngroundedRentaIncomepairing the declared base-reading facts with the base-less rows those bindings consume.
- unrouted_ledger_renta_income_quantities(revision, observations)[source]¶
Return independent quantities the rows carry that no binding on
revisiondraws.The third renta-income screen, and it watches an axis the other two cannot see.
unsupported_ledger_renta_income_observations()asks whether a ROW is selected by some binding;ungrounded_ledger_renta_income_observations()asks whether a consumed row carried the substrate its binding’s fact assumes. Both key on the row. This one keys on the QUANTITY.The distinction is load-bearing because every
RentaIncomeObservationis built withtarget_casilla_id = "01"regardless of which fact a binding reads off it (see the note in the M1300003-m130-income-cumulative.tomlbindings fragment). A row therefore matches the income bindings on that key and counts as consumed — while a SECOND, independent quantity it carries, the retención suffered, reaches nothing at all. Drop thewithheld_amount_sumbinding from a revision and the row-level screen stays silent: every row is still consumed, for its income. The taxpayer’s whole retención credit disappears with a clean screen on both sides, which is precisely the silent under-declaration the screens exist to prevent.Alternative MEASURES of one quantity are excluded (
_RENTA_INCOME_ALTERNATIVE_MEASURE_FACTS): a revision picks one income measure and omitting the other two is correct, so demanding all three would fire on every revision and train the operator to ignore the advisory. Only a genuinely independent quantity is screened.Reports nothing when the rows carry nothing: a taxpayer who suffered no retención has a zero total, which is a legitimate zero rather than a modelling gap, and this screen must not manufacture a finding from it.
- Parameters:
revision (
ModeloRevision) – TheModeloRevisionwhose renta-income bindings decide which facts are drawn.observations (
Iterable[RentaIncomeObservationProtocol]) – Actividad-económica income observations to screen.
- Return type:
tuple[UnroutedLedgerQuantity[RentaIncomeObservationProtocol],...]- Returns:
One
UnroutedLedgerQuantityper uncovered non-zero quantity, ordered by fact name. Empty when every quantity the rows carry is drawn.
- validate_ledger_renta_income_aggregation_binding(binding)[source]¶
Validate a
ledger_renta_income_aggregationbinding at registry-build time.Accumulating
list[str]validator overLedgerRentaIncomeProvider; runs the fact/aggregation-op invariant at build time throughinvariant_diagnostics(), whose raise-style body isvalidate_ledger_renta_income_aggregation_binding_definition().- Return type:
- Parameters:
binding (BindingDefinition)
- class LedgerRentaIncomeProvider(**data)[source]¶
Bases:
BaseModelValidated form of a ledger_renta_income_aggregation binding selector.
modelonames the declaration series the aggregation feeds: M130’s cumulative quarter, M100’s annual ejercicio, or M131’s agrarian quarterly volumen de ingresos.target_casilla_idis the casilla that receives the total. The M131 leg is NOT cumulative – art. 110.1.c) fixes its payment on el volumen de ingresos del trimestre – and its projection applies two filters the others do not: the art. 110.1.c) activity set, and the exclusion of subvenciones de capital and indemnizaciones. Both live in the projection rather than in this selector because they decide which rows EXIST as observations, not which observations a binding claims.factis REQUIRED and carries no default. Each accepted value names a different legal measure of the same rows, so a default would silently pick a legal claim on the taxpayer’s behalf:cash_received_sumis the raw bank-credited amount — net of any retención practicada and possibly IVA-inclusive — whileingresos_integros_sumis the ingresos íntegros the M130 instructions actually ask for. An omitting binding fails registry validation naming the accepted set rather than inheriting the weakest measure.factcontrols which aggregation path is applied:"ingresos_integros_sum"sums the fiscally computable ingreso per observation:taxable_base_amount(the IVA-exclusive base imponible) when the transaction carries an explicit IVA tagging, falling back togross_amountwhen no base is declared — the canonical ingresos-íntegros path feeding casilla"01". The AEAT M130 instructions define casilla 01 as the “ingresos íntegros fiscalmente computables”; IVA repercutido is collected on behalf of Hacienda and is not computable income, so a tagged invoice contributes its base, never its IVA-inclusive gross."cash_received_sum"sumsRentaIncomeObservation.gross_amount(raw.amountor its business fraction) across the window, ignoring any declared taxable base. Named for what it computes: the cash the bank credited, which is neither gross of retención nor IVA-exclusive and is therefore NOT the ingresos-íntegros measure."taxable_base_sum"sumsRentaIncomeObservation.taxable_base_amount(the IVA-exclusive base imponible). Observations whosetaxable_base_amountisNonedeclare no base and contribute nothing to this sum;ungrounded_ledger_renta_income_observations()surfaces every such row so the omission is visible rather than silent."withheld_amount_sum"sums the IRPF amount withheld at source from net-paid professional receipts.
- Parameters:
data (Any)
- kind: Literal[BindingSourceKind.LEDGER_RENTA_INCOME_AGGREGATION]¶
- modelo: Modelo¶
- target_casilla_id: CasillaId¶
- fact: LedgerIncomeFactValue¶