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:
AeatErrorA registry expression has no closed-form Sheets equivalent.
- 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:
- Parameters:
expression (FormulaExpression)
layout (SheetLayout)
- is_translatable(expression, *, layout)[source]¶
Return whether expression has a closed-form Sheets translation.
This is the honest
translate_formulawould-succeed probe: it attempts the full closed-form compilation against the same layout and reports failure iff aTranslationErroris raised (an unsupported op such as the M303 régimen-simplificadom303_resolve_modulos_iva_cuota_devengadacustom 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:
- Parameters:
expression (FormulaExpression)
layout (SheetLayout)