aeat.domain.calculations.registry._formula_runtime_ops module

Formula-runtime operation helpers for registry calculations.

The formula evaluator delegates arithmetic dispatch, dated parameter lookup, rounding, and input validation here while executing ModeloRevision formula graphs. Helpers raise RegistryValidationError so domain.calculations.registry._formula_runtime.calculate_registry_snapshot() reports contract failures through the registry error channel.

See also

domain.calculations.registry._formula_runtime

Snapshot evaluator that calls these helpers while materialising RegistrySnapshot outputs.

domain.calculations.registry._runtime_graph

Formula graph walkers that discover the casilla, binding, relation, and parameter refs consumed before operation dispatch starts.

domain.calculations.registry.ValidatedRegistryAuthority

Registry authority loaded by read_parameter() for ad hoc parameter reads outside snapshot execution.

exception UnresolvedFormulaDependencyError(dependency_ids)[source]

Bases: RegistrySnapshotError

Raised internally when a non-blocking source gap makes a formula unresolved.

Shared between _formula_runtime and its per-family op-evaluator siblings (e.g. _formula_runtime_irnr) so a family module can signal a deferred dependency without importing back into the dispatcher module.

Parameters:

dependency_ids (tuple[str, ...])

Return type:

None

code: ClassVar[ErrorCode]
class RegistryUnresolvedOutcomeReason(*values)[source]

Bases: StrEnum

Closed reason catalogue for typed formula outcomes with no Decimal value.

M210_BASELINE_TIPO_DEFERRED
M210_CONVENIO_RATE_MISSING
exception UnresolvedFormulaOutcomeError(reason, *, context)[source]

Bases: RegistrySnapshotError

Raised internally when a formula emits a typed unresolved outcome.

Parameters:
Return type:

None

code: ClassVar[ErrorCode]
numeric_casilla_value(casilla_id, ctx)[source]

Read a resolved numeric casilla value from the evaluation context.

Generic accessor shared by the M210/IRNR, M131 módulos, and M303 módulos IVA formula-op families; each raises UnresolvedFormulaDependencyError the same way for a casilla deferred by a non-blocking source gap.

Return type:

Decimal

Parameters:
  • casilla_id (CasillaId)

  • ctx (_EvalContext)

evaluate_args_op(op, args)[source]

Evaluate a resolved formula operation over decimal operands.

Operation names mirror FormulaExpression op values consumed by domain.calculations.registry._formula_runtime.calculate_registry_snapshot().

Return type:

Decimal

Parameters:
resolve_bracket(parameter, base, date_context)[source]

Resolve a bracket-table ParameterDefinition for a base amount.

The parameter’s bracket date axis must be present in date_context so registry-authored validity windows select exactly one bracket row.

Return type:

Decimal

Parameters:
resolve_parameter(parameter, date_context)[source]

Resolve one dated value from a ParameterDefinition.

Exactly one DatedValue must match the selected date axes for the parameter lookup to be deterministic.

Return type:

Decimal

Parameters:
apply_rounding(value, rounding)[source]

Apply a registry rounding rule to a decimal formula result.

money-2 uses core.money.round_to_cents(); integer uses half-up quantization for registry-authored integer targets.

Return type:

Decimal

Parameters:
reject_non_decimal(items, label)[source]

Reject non-decimal values before formula runtime consumption.

Return type:

None

Parameters:
validated_decimal_input_casilla_ids(inputs, *, revision)[source]

Canonicalise decimal input keys against a ModeloRevision.

Raw string keys become validated CasillaId values, then domain.calculations.registry._casilla_membership.undeclared_casilla_ids() rejects inputs outside the revision’s declared casilla set.

Return type:

dict[TypeAliasType, Decimal]

Parameters:
reject_non_string(values, label)[source]

Reject empty or non-string external values before registry validation.

Return type:

None

Parameters:
reject_unknown_external_values(items, known_ids, label)[source]

Reject external ids not declared by the current registry snapshot.

Return type:

None

Parameters:
read_parameter(modelo_id, revision_id, parameter_id, *, date_context, registry_root=None)[source]

Read a registry parameter through ValidatedRegistryAuthority.

The ad hoc public helper loads the same validated registry authority used by snapshot callers, narrows to the selected ModeloRevision, and delegates the dated value lookup to resolve_parameter().

Return type:

Decimal

Parameters: