aeat.domain.calculations.registry._binding_selector_utils module

Shared selector normalization and field-validator helpers for registry bindings.

class BindingFixedExportSelector(**data)[source]

Bases: BaseModel

Typed fixed-width export projection carried by a binding selector.

Parameters:
  • record (str)

  • offset (int)

  • length (int)

  • data_type (Literal['text', 'integer', 'decimal', 'money', 'date', 'boolean'])

  • field (str | None)

record: str
offset: int
length: int
data_type: BindingExportDataType
field: str | None
class BindingRowExportSelector(**data)[source]

Bases: BaseModel

Typed row-field export projection carried by a binding selector.

Parameters:
  • record (str)

  • row_field (str)

record: str
row_field: str
class BindingRowSetSelector(**data)[source]

Bases: BaseModel

Typed row-set projection carried by a row-producing binding selector.

Parameters:
  • fact (Literal['row_field'])

  • row_field (str)

  • grouping (str)

  • record (str | None)

fact: Literal['row_field']
row_field: str
grouping: str
record: str | None
selector_as_dict(binding)[source]

Return a plain selector mapping without injected source metadata.

Return type:

dict[str, object]

Parameters:

binding (DataBindingDefinition)

class BooleanBindingEncodedValue(**data)[source]

Bases: BaseModel

One accepted decimal encoding of a boolean-casilla manual_input binding.

A manual_input binding whose selector declares data_type = "boolean" (the Modelo 100 estimación-directa modality flag is the canonical case) is consumed by the registry formulas as a numeric 1 / 0 operand. The operator therefore supplies a decimal on the --binding channel, yet the accepted values and their meaning are opaque from the raw DataBindingDefinition. This record makes one accepted value explicit: encoded_value is the decimal the operator types, boolean_meaning is the affirmative/negative sense it carries, and registry_value is the underlying casilla token the boolean maps to (the selector’s declared true_value / false_value).

Parameters:
  • encoded_value (str)

  • boolean_meaning (bool)

  • registry_value (str)

encoded_value: str
boolean_meaning: bool
registry_value: str
boolean_binding_encoded_values(binding)[source]

Return the decimal encoding of a boolean-casilla manual_input binding.

The result is empty for every binding that is not a boolean-casilla manual_input selector, so a caller can read a non-empty result as “this binding is a decimal-encoded boolean flag”. The encoding follows the registry convention that a boolean operand is consumed as 1 (true) / 0 (false); each sense is paired with the selector’s declared true_value / false_value casilla token, so the mapping is derived from the binding definition, never hardcoded per modelo.

Return type:

tuple[BooleanBindingEncodedValue, ...]

Returns:

Zero or two BooleanBindingEncodedValue rows.

Parameters:

binding (DataBindingDefinition)

binding_export_selector(binding)[source]

Return the typed export projection embedded in binding.selector.

Binding source-family selectors remain authoritative for business facts. Export record resolution only needs the official record-coordinate projection; this helper parses that projection once into a typed fixed-field or row-field selector instead of letting callers probe the raw selector map.

Return type:

BindingFixedExportSelector | BindingRowExportSelector | None

Parameters:

binding (DataBindingDefinition)

binding_row_set_selector(binding)[source]

Return the typed row-set projection embedded in binding.selector.

Source-family selectors remain the authority for fact-specific filters. Row-set consumers only need the common fact = "row_field" projection that names the detail grouping and the emitted row field, so callers parse that projection once instead of probing the raw selector map.

Return type:

BindingRowSetSelector | None

Returns:

The parsed BindingRowSetSelector, or None when the binding selector does not declare a row-set projection.

Parameters:

binding (DataBindingDefinition)

selector_against_model(binding, selector_model)[source]

Validate binding.selector against selector_model, accumulating diagnostics.

Projects the selector through selector_as_dict() (the same normalised mapping the resolve-time helpers see, so the build gate is never stricter than runtime), validates against the strict pydantic model, and returns the underlying field message verbatim in a diagnostic naming the binding id, its source, and the violated model. The underlying pydantic error is preserved rather than flattened to a generic “malformed selector”, matching the shape the counterpart/withholding build-time lift already emits.

Returns an empty list when the selector validates.

Return type:

list[str]

Parameters:
invariant_diagnostics(binding, label, check)[source]

Run a raise-style op/fact invariant check and collect its diagnostic.

The detail-record, previous-filing, counterpart, withholding, invoice, and ledger families enforce their op/fact cross-invariants by raising RegistryValidationError. This adapter runs the raising check and converts the raised message into one accumulating diagnostic string naming the binding id, its source, and the label family, preserving the underlying field message. Returns an empty list when the invariant holds.

Return type:

list[str]

Parameters:
uppercase_alpha_code(field_label)[source]

Build a field validator that rejects a non-uppercase-alphabetic code.

Shared by the binding observation models whose ISO country / member-state / currency codes must be uppercase alphabetic; field_label names the field in the raised RegistryValidationError.

Return type:

Callable[[type, str], str]

Parameters:

field_label (str)

intracommunity_clave_validator()[source]

Build the shared intracommunity_clave field validator.

Both InvoiceObservation and CounterpartAggregationObservation carried a byte-identical intracommunity_clave field validator: a clave is optional, must be uppercase, and must be one of the closed AEAT clave de operación set. The single factory replaces both copies.

Return type:

Callable[[type, str | None], str | None]

validate_rectification_fields(observation)[source]

Enforce the rectification-field coupling shared by the invoice families.

A rectification observation must declare rectified_year, rectified_period and rectified_base_previous; a non-rectification observation must declare none of them. InvoiceObservation and CounterpartAggregationObservation carried a byte-identical _validate_rectification model validator; this one shared check replaces both, raising RegistryValidationError on a violation.

Return type:

None

Parameters:

observation (_RectifiableObservation)

unique_tuple(label)[source]

Build a field validator that rejects duplicate entries in a tuple field.

Shared by the binding requirement models; label names the offending tuple in the raised RegistryValidationError ("<label> entries must be unique").

Return type:

Callable[[type, tuple[str, ...]], tuple[str, ...]]

Parameters:

label (str)