cadrumo.domain.calculations.registry.export_value_policy module

Canonical value-policy projection for fixed-width registry export fields.

class SelectedUnselectedFlag(*values)[source]

Bases: StrEnum

The two ASCII characters a selected/unselected export field may contain.

Named because the tokens carry meaning the digits do not: the field is a checkbox, not a quantity. Both the projector and the validator tested the pair separately, and both error messages already said “exactly ASCII 0 or 1” – the rule was stated three times and declared none.

UNSELECTED
SELECTED
SELECTED_UNSELECTED_VALUES: Final[frozenset[SelectedUnselectedFlag]]

Both flag characters, derived from the enum so the two checks cannot disagree.

class ExportValuePolicy(*values)[source]

Bases: StrEnum

Closed runtime transformations from semantic values to AEAT wire tokens.

SELECTED_1_UNSELECTED_0
FOUR_DIGIT_YEAR_FINAL_TWO_DIGITS
UNSIGNED_INTEGER
IMPLIED_DECIMAL
YYYYMMDD
DDMMYYYY
ENUMERATED_DIGITS
DIGIT_STRING
IDENTIFIER_DIGITS
FOUR_DIGIT_YEAR
TWO_DIGIT_MONTH
TWO_DIGIT_DAY
MISTYPED_ALPHANUMERIC_TEXT

A slot AEAT typed numeric that carries alphanumeric prose. AEAT’s own Nota 1 defines the column exactly – “A (Alfabetico) An (Alfanumerico), Num (Numerico sin signo) o N (Numerico con signo)” – so “Num” on a 100-position “Descripcion del elemento patrimonial” is a publication error, not a convention. There is no numeric reading of that slot to derive, and the surrounding rows are typed identically, so the mistyping is not recoverable from the design. This policy is how a REVIEWED profile states the real representation; it is never inferred from width or description.

INTEGER_PART

AEAT prints some quantities as a parent row subdivided into a printed “Parte entera” row and a printed “Parte decimal” row. The record-design parser folds that subdivision on exact tiling and the export IR descends to the LEAVES, so a layout necessarily carries two fields where the declared value is one – and the export path resolves values per CASILLA, handing BOTH leaves the identical whole value. These two policies are how each leaf states which part of that value it writes; the field’s own declared length fixes how many digits the part occupies. Neither part is invertible alone, so parsing one retains the wire token rather than presenting itself as a reconstructed quantity.

FRACTIONAL_DIGITS
class ParsedExportPolicyWireValue(policy, raw)[source]

Bases: object

Validated wire value retained when its source semantic value is not invertible.

Parameters:
policy: ExportValuePolicy
raw: str
coerce_export_value_policy(value)[source]

Hydrate a declared policy token while leaving unknown values to strict validation.

Return type:

object

Parameters:

value (object)

export_value_policy_wire_length(policy)[source]

Return a fixed policy width, or None when the field declares it.

Return type:

int | None

Parameters:

policy (ExportValuePolicy)

project_export_value(policy, value)[source]

Project one semantic value to its exact declared wire token.

None is deliberately inert: it is not an inference hook and does not select a policy from field width, type, identifier, or historical layout.

Return type:

object

Parameters:
policy_defines_absent_slot(policy)[source]

Whether policy assigns its OWN meaning to a slot carrying no value.

An unselected checkbox is not an absent number: its policy declares that the empty slot means 0, so the value must reach the projector. Every other policy leaves absence to the field’s declared blank fill, which is what AEAT’s designs state (“los campos numericos que no tengan contenido se rellenaran a ceros”). Named rather than inlined at the call site so the exception stays one auditable list instead of a condition readers must re-derive.

Return type:

bool

Parameters:

policy (ExportValuePolicy | None)

validate_export_wire_value(policy, raw)[source]

Refuse a wire token that contradicts its declared value policy.

Return type:

None

Parameters:
normalize_parsed_export_policy_value(policy, raw, parsed)[source]

Return a renderer-admissible semantic value for canonical parsed wire.

Return type:

TypeAliasType

Parameters: