aeat.application.storage.calc_sheets._translator module

Closed-form translator from registry FormulaExpression ASTs to Google Sheets A1 formula strings.

The translator is the parity contract: a registry op evaluates to the same per-casilla rounded Decimal locally and in Sheets if and only if the formula this translator emits is a closed-form equivalent of the local Decimal arithmetic.

Per-casilla rounding is applied by the engine driver, not by this translator — translate_formula returns the unrounded expression and the caller wraps it in ROUND(expr, scale) according to the casilla’s rounding rule. That separation keeps the translator a pure expression compiler and concentrates rounding policy in one place.

Unsupported leaves and ops raise TranslationError. Today bindings and relations are unsupported in the closed-form path (the caller must pre-resolve binding values into Tarifas/Entradas cells before invoking the engine); TranslationError carries enough context for the caller to surface a typed CLI error.

exception TranslationError(message, *, op=None, hint=None)[source]

Bases: AeatError

A registry expression has no closed-form Sheets equivalent.

Parameters:
  • message (str)

  • op (str | None)

  • hint (str | None)

Return type:

None

code: ClassVar[ErrorCode]
translate_formula(expression, *, layout)[source]

Compile a registry formula expression to a Sheets A1 expression.

The returned string does NOT have a leading “=” sign and is NOT yet wrapped in ROUND(). It is the raw arithmetic body the engine will rounded-wrap based on the target casilla’s rounding rule.

Return type:

str

Parameters:
is_translatable(expression, *, layout)[source]

Return whether expression has a closed-form Sheets translation.

This is the honest translate_formula would-succeed probe: it attempts the full closed-form compilation against the same layout and reports failure iff a TranslationError is raised (an unsupported op such as the M303 régimen-simplificado m303_resolve_modulos_iva_cuota_devengada custom runtime dispatch, or a leaf the layout has not materialised). It never re-implements the supported-op set, so it cannot drift from the real translator.

Return type:

bool

Parameters: