aeat.domain.calculations.registry._schema_surfaces module¶
Casilla, relation, export, and record schema models.
- class CasillaContinuidadEvolutionDefinition(**data)[source]¶
Bases:
RegistryModelDeclared cross-revision evolution for one casilla continuity chain.
- Parameters:
id (RecordId)
continuidad_id (Annotated[str, FieldInfo(annotation=NoneType, required=True, metadata=[MinLen(min_length=1), MaxLen(max_length=128), _PydanticGeneralMetadata(pattern='^[a-z0-9][a-z0-9._:-]*[a-z0-9]$|^[a-z0-9]$')])])
from_revision (RevisionId)
to_revision (RevisionId)
evolution_kind (Literal['unchanged', 'label_evolved', 'legal_refs_evolved', 'label_and_legal_refs_evolved', 'repurposed', 'retired'])
legal_refs (Annotated[tuple[LegalRefId, ...], FieldInfo(annotation=NoneType, required=True, metadata=[MinLen(min_length=1)])])
source_refs (Annotated[tuple[SourceRefId, ...], FieldInfo(annotation=NoneType, required=True, metadata=[MinLen(min_length=1)])])
- id: RecordId¶
- continuidad_id: ContinuidadId¶
- from_revision: RevisionId¶
- to_revision: RevisionId¶
- evolution_kind: Literal['unchanged', 'label_evolved', 'legal_refs_evolved', 'label_and_legal_refs_evolved', 'repurposed', 'retired']¶
- legal_refs: LegalRefs¶
- source_refs: SourceRefs¶
- class CasillaAlias(**data)[source]¶
Bases:
RegistryModelA label variant for a casilla, carrying its own legal grounding.
Used by Plan C’s semantic-role validator: two casillas in different modelos can share a
semantic_roleeven though their primarylabelstrings differ verbatim, provided each declares the divergent phrasing via analiasesentry with a documented BOE or AEAT source.- Parameters:
- label: str¶
- legal_refs: LegalRefs¶
- source_refs: SourceRefs¶
- class CasillaConstraints(**data)[source]¶
Bases:
RegistryModelDeclarative value constraints applied after a casilla is evaluated.
Captures the legal sign / range rules AEAT mandates per LIRPF / LIVA / LIS articles: a withholding casilla cannot carry a negative value, a deductibility cap restricts the maximum, a non-negativity floor on a cuota líquida prevents arithmetic underflow propagating through downstream formulas.
Each constraint declares its own legal grounding so the engine can surface a BOE permalink in the violation envelope when a computed value falls outside the declared bounds. The runtime raises a typed CasillaConstraintViolationError; the Sheets apply adapter renders the same record as a setDataValidation rule on the corresponding cell so the operator sees the constraint directly in the workbook UI.
- Parameters:
sign (Literal['any', 'non_negative', 'non_positive'])
min_value (Annotated[Decimal, BeforeValidator(func=~aeat.domain.calculations.registry._schema_scalars._coerce_decimal, json_schema_input_type=PydanticUndefined)] | None)
max_value (Annotated[Decimal, BeforeValidator(func=~aeat.domain.calculations.registry._schema_scalars._coerce_decimal, json_schema_input_type=PydanticUndefined)] | None)
pattern (str | None)
min_length (int | None)
max_length (int | None)
legal_refs (Annotated[tuple[LegalRefId, ...], FieldInfo(annotation=NoneType, required=True, metadata=[MinLen(min_length=1)])])
source_refs (Annotated[tuple[SourceRefId, ...], FieldInfo(annotation=NoneType, required=True, metadata=[MinLen(min_length=1)])])
- sign: Literal['any', 'non_negative', 'non_positive']¶
- min_value: DecimalValue | None¶
- max_value: DecimalValue | None¶
- pattern: str | None¶
- min_length: int | None¶
- max_length: int | None¶
- enum: tuple[str, ...] | None¶
- legal_refs: LegalRefs¶
- source_refs: SourceRefs¶
- violates(value)[source]¶
Return a short reason string if a Decimal value violates this constraint, else None.
Numeric-only violation check preserved for downstream consumers of computed casilla values. Text constraints (pattern, min_length, max_length, enum) are surfaced through the sibling
violates_text()method.
- violates_text(value)[source]¶
Return a short reason string if a text value violates the text constraints, else None.
Checks the four text-shape constraints introduced by Plan B:
pattern,min_length,max_length, andenum. Used by consumers that resolve a casilla value into a string at evaluation time.
- class CasillaDefinition(**data)[source]¶
Bases:
RegistryModelA single AEAT casilla within a modelo revision.
idis the canonical reference identity.numberandsegmentoare reviewed AEAT record-design metadata. For single-segment modelossegmentois unset andnumberalone is unique within the revision. Multi-segment AEAT modelos (e.g. Modelo 200) reuse the same five-digitnumberacross distinct record segments with a different meaning in each; those casillas carry the AEAT record-segment code insegmentoto disambiguate metadata.- Parameters:
id (CasillaId)
number (str)
segmento (str | None)
label (str)
data_type (Literal['decimal', 'money', 'integer', 'ratio', 'text', 'boolean', 'nif', 'year', 'period_code', 'country_code', 'iban', 'name', 'nif_iva', 'ccaa_code', 'province_code', 'postal_code', 'municipality_code', 'bic', 'date'])
required (bool)
input_kind (Annotated[InputKind, BeforeValidator(func=~aeat.domain.calculations.registry._schema_input_kind._coerce_input_kind, json_schema_input_type=PydanticUndefined)])
formula (FormulaId | None)
binding (BindingId | None)
alternate_bindings (tuple[BindingId, ...])
export_refs (tuple[ExportFieldId, ...])
constraints (CasillaConstraints | None)
form_number (str | None)
continuidad_id (Annotated[str, FieldInfo(annotation=NoneType, required=True, metadata=[MinLen(min_length=1), MaxLen(max_length=128), _PydanticGeneralMetadata(pattern='^[a-z0-9][a-z0-9._:-]*[a-z0-9]$|^[a-z0-9]$')])] | None)
semantic_role (str | None)
semantic_role_cardinality (Literal['shared', 'intentional_singleton'])
semantic_role_cardinality_reason (str | None)
aliases (tuple[CasillaAlias, ...])
internal_only (bool)
legal_refs (Annotated[tuple[LegalRefId, ...], FieldInfo(annotation=NoneType, required=True, metadata=[MinLen(min_length=1)])])
source_refs (Annotated[tuple[SourceRefId, ...], FieldInfo(annotation=NoneType, required=True, metadata=[MinLen(min_length=1)])])
- id: CasillaId¶
- number: str¶
- segmento: str | None¶
- label: str¶
- localized_labels: dict[str, str]¶
- localized_help: dict[str, str]¶
- section: tuple[str, ...]¶
- data_type: Literal['decimal', 'money', 'integer', 'ratio', 'text', 'boolean', 'nif', 'year', 'period_code', 'country_code', 'iban', 'name', 'nif_iva', 'ccaa_code', 'province_code', 'postal_code', 'municipality_code', 'bic', 'date']¶
- required: bool¶
- input_kind: InputKindValue¶
- formula: FormulaId | None¶
- binding: BindingId | None¶
- alternate_bindings: tuple[BindingId, ...]¶
- export_refs: tuple[ExportFieldId, ...]¶
- constraints: CasillaConstraints | None¶
- form_number: str | None¶
- continuidad_id: ContinuidadId | None¶
- semantic_role: str | None¶
- semantic_role_cardinality: Literal['shared', 'intentional_singleton']¶
- semantic_role_cardinality_reason: str | None¶
- aliases: tuple[CasillaAlias, ...]¶
- internal_only: bool¶
- legal_refs: LegalRefs¶
- source_refs: SourceRefs¶
- class CalculationCompletenessCasilla(**data)[source]¶
Bases:
RegistryModelOne required canonical
casilla.idin a calculation-completeness manifest.casilla_idis the authoritative reference key consumed by the validator.numberandsegmentoremain official record-design metadata for drift review: the validator cross-checks them against the referenced casilla, but no consumer may resolve the manifest by those metadata fields.The manifest enumerates only the casillas inside a modelo’s calculation closure — formula targets, the casillas referenced inside any formula expression, formula and binding endpoint casillas, and verification-expectation operands. Pure accounting-statement data-entry fields that feed no calculation are intentionally absent from this required set.
- casilla_id: CasillaId¶
- number: str¶
- segmento: str | None¶
- class CalculationCompletenessManifest(**data)[source]¶
Bases:
RegistryModelThe required calculation-closure casilla set for a modelo revision.
Enumerates the canonical
casilla.idvalues in a modelo’s calculation closure — the casillas the cross-connecting calculation engine traverses: every formula target, every casilla referenced inside a formula expression, every binding and relation endpoint casilla, and every verification-expectation operand. It is derived from the official AEAT Diseño de Registros intersected with the modelo’s calculation surface — Diseño-authoritative on each casilla’s segment, number, and label, but the checked-in reference key is the registry’s canonicalcasilla.id. The segment/number metadata is retained as reviewed evidence and cross-checked against that id.The registry validator enforces
manifest-required ⊆ declaredby canonicalcasilla.idplus a segment/number metadata check and alegal_refs/source_refsgrounding check on each required casilla. A casilla the revision declares but the manifest does not list (a pure accounting-statement field) is not a failure.manual_extractionflags a manifest authored from a manual read of a PDF-only Diseño that resists machine extraction; the off-load-path drift re-verification skips the machine re-derivation for such manifests and recordsmanual_extraction_reasoninstead of failing silently.- Parameters:
source_ref (SourceRefId)
casillas (tuple[CalculationCompletenessCasilla, ...])
manual_extraction (bool)
manual_extraction_reason (str | None)
legal_refs (Annotated[tuple[LegalRefId, ...], FieldInfo(annotation=NoneType, required=True, metadata=[MinLen(min_length=1)])])
source_refs (Annotated[tuple[SourceRefId, ...], FieldInfo(annotation=NoneType, required=True, metadata=[MinLen(min_length=1)])])
- source_ref: SourceRefId¶
- casillas: tuple[CalculationCompletenessCasilla, ...]¶
- manual_extraction: bool¶
- manual_extraction_reason: str | None¶
- legal_refs: LegalRefs¶
- source_refs: SourceRefs¶
- class AlgorithmProviderDefinition(**data)[source]¶
Bases:
RegistryModel- Parameters:
id (str)
import_path (str)
callable_name (str)
deterministic (Literal[True])
side_effect_free (Literal[True])
trace_contract (str)
legal_refs (Annotated[tuple[LegalRefId, ...], FieldInfo(annotation=NoneType, required=True, metadata=[MinLen(min_length=1)])])
source_refs (Annotated[tuple[SourceRefId, ...], FieldInfo(annotation=NoneType, required=True, metadata=[MinLen(min_length=1)])])
- id: str¶
- import_path: str¶
- callable_name: str¶
- deterministic: Literal[True]¶
- side_effect_free: Literal[True]¶
- allowed_input_schema: Mapping[str, str]¶
- output_schema: Mapping[str, str]¶
- trace_contract: str¶
- legal_refs: LegalRefs¶
- source_refs: SourceRefs¶
- class AlgorithmBindingDefinition(**data)[source]¶
Bases:
RegistryModel- Parameters:
id (str)
provider (str)
target_casilla_id (CasillaId)
inputs (Mapping[str, BindingId | CasillaId | ParameterId | RelationId])
constants (tuple[ParameterId, ...])
legal_refs (Annotated[tuple[LegalRefId, ...], FieldInfo(annotation=NoneType, required=True, metadata=[MinLen(min_length=1)])])
source_refs (Annotated[tuple[SourceRefId, ...], FieldInfo(annotation=NoneType, required=True, metadata=[MinLen(min_length=1)])])
- id: str¶
- provider: str¶
- target_casilla_id: CasillaId¶
- inputs: Mapping[str, BindingId | CasillaId | ParameterId | RelationId]¶
- output_casilla_ids: Mapping[str, CasillaId]¶
- constants: tuple[ParameterId, ...]¶
- legal_refs: LegalRefs¶
- source_refs: SourceRefs¶
- class RelationRevisionSelector(**data)[source]¶
Bases:
RegistryModel- Parameters:
- year: int | None¶
- year_from: int | None¶
- year_to: int | None¶
- filing_year_delta: int | None¶
- class RelationPeriodAlignment(**data)[source]¶
Bases:
RegistryModel- Parameters:
- mode: Literal['previous_quarter', 'prior_pagos_cumulative'] | None¶
- source_periods: Literal['quarters', 'months', 'annual_summary'] | None¶
- source_period_kind: Literal['quarterly'] | None¶
- source_period: str | None¶
- target_period: str | None¶
- filing_year_delta: int | None¶
- class RelationDefinition(**data)[source]¶
Bases:
RegistryModel- Parameters:
id (RelationId)
kind (Literal['previous_period', 'annual_summary', 'cross_model_output'])
dependency_role (Literal['profile_schedule', 'periodic_to_annual_summary', 'instalment_to_final_settlement', 'direct_calculation', 'factual_evidence'])
source_modelo (ModeloId)
source_revision_selector (RelationRevisionSelector)
source_casilla_id (CasillaId)
target_binding (BindingId)
period_alignment (RelationPeriodAlignment)
source_period_offset_from_target (int | None)
aggregation (RelationAggregation | None)
legal_refs (Annotated[tuple[LegalRefId, ...], FieldInfo(annotation=NoneType, required=True, metadata=[MinLen(min_length=1)])])
source_refs (Annotated[tuple[SourceRefId, ...], FieldInfo(annotation=NoneType, required=True, metadata=[MinLen(min_length=1)])])
- id: RelationId¶
- kind: Literal['previous_period', 'annual_summary', 'cross_model_output']¶
- dependency_role: Literal['profile_schedule', 'periodic_to_annual_summary', 'instalment_to_final_settlement', 'direct_calculation', 'factual_evidence']¶
- source_modelo: ModeloId¶
- source_revision_selector: RelationRevisionSelector¶
- source_casilla_id: CasillaId¶
- target_binding: BindingId¶
- period_alignment: RelationPeriodAlignment¶
- source_periods: tuple[str, ...]¶
- target_periods: tuple[str, ...]¶
- source_period_offset_from_target: int | None¶
- aggregation: RelationAggregation | None¶
- legal_refs: LegalRefs¶
- source_refs: SourceRefs¶
- class ExportFieldDefinition(**data)[source]¶
Bases:
RegistryModel- Parameters:
id (ExportFieldId)
offset (int | None)
length (int | None)
kind (Annotated[CasillaFieldKind, BeforeValidator(func=~aeat.domain.calculations._export_field_kind._coerce_casilla_field_kind, json_schema_input_type=PydanticUndefined)])
casilla_id (CasillaId | None)
binding (BindingId | None)
literal (str | None)
header_key (str | None)
draft_attribute (Literal['modelo', 'period', 'profile_tax_id', 'filing_year', 'period_code'] | None)
computed_key (Literal['envelope_closing_tag'] | None)
data_type (Literal['text', 'integer', 'decimal', 'money', 'date', 'boolean'])
required (bool)
padding (Literal['left_zero', 'left_space', 'right_space', 'none'])
justification (Literal['left', 'right', 'none'])
date_format (str | None)
signed (bool)
legal_refs (Annotated[tuple[LegalRefId, ...], FieldInfo(annotation=NoneType, required=True, metadata=[MinLen(min_length=1)])])
source_refs (Annotated[tuple[SourceRefId, ...], FieldInfo(annotation=NoneType, required=True, metadata=[MinLen(min_length=1)])])
- id: ExportFieldId¶
- offset: int | None¶
- length: int | None¶
- kind: CasillaFieldKindValue¶
- casilla_id: CasillaId | None¶
- binding: BindingId | None¶
- literal: str | None¶
- header_key: str | None¶
- draft_attribute: Literal['modelo', 'period', 'profile_tax_id', 'filing_year', 'period_code'] | None¶
- computed_key: Literal['envelope_closing_tag'] | None¶
- data_type: Literal['text', 'integer', 'decimal', 'money', 'date', 'boolean']¶
- required: bool¶
- padding: Literal['left_zero', 'left_space', 'right_space', 'none']¶
- justification: Literal['left', 'right', 'none']¶
- date_format: str | None¶
- signed: bool¶
- legal_refs: LegalRefs¶
- source_refs: SourceRefs¶
- class RecordDiscriminator(**data)[source]¶
Bases:
RegistryModelRecord-shape discriminator for record types that share literal prefixes.
A record’s literal-prefix matcher cannot tell two records apart when they share their leading literal fields (AEAT models several Tipo-2 record sub-shapes that all start with the same record-type literal). The discriminator declares a contiguous byte range whose populated-or-blank pattern uniquely identifies this record subtype, letting the parser pick the correct record while reading binding-row sequences.
- offset: int¶
- length: int¶
- requires: Literal['blank', 'non_blank']¶
- class ExportRecordDefinition(**data)[source]¶
Bases:
RegistryModel- Parameters:
id (RecordId)
record_type (str)
order (int)
encoding (str)
line_ending (Literal['crlf', 'lf', 'none'])
required (bool)
repeat (Literal['binding_rows'] | None)
binding_record (str | None)
discriminator (RecordDiscriminator | None)
requires_positive_casilla_id (CasillaId | None)
fields (tuple[ExportFieldDefinition, ...])
- id: RecordId¶
- record_type: str¶
- order: int¶
- encoding: str¶
- line_ending: Literal['crlf', 'lf', 'none']¶
- required: bool¶
- repeat: Literal['binding_rows'] | None¶
- binding_record: str | None¶
- row_field_casilla_ids: Mapping[str, CasillaId]¶
- discriminator: RecordDiscriminator | None¶
- requires_positive_casilla_id: CasillaId | None¶
- fields: tuple[ExportFieldDefinition, ...]¶
- class ExportLayoutDefinition(**data)[source]¶
Bases:
RegistryModel- Parameters:
id (ExportLayoutId)
format (Literal['fixed_width', 'xml_dictionary'])
dictionary_source_ref (SourceRefId | None)
source_refs (Annotated[tuple[SourceRefId, ...], FieldInfo(annotation=NoneType, required=True, metadata=[MinLen(min_length=1)])])
legal_refs (Annotated[tuple[LegalRefId, ...], FieldInfo(annotation=NoneType, required=True, metadata=[MinLen(min_length=1)])])
records (tuple[ExportRecordDefinition, ...])
- id: ExportLayoutId¶
- format: Literal['fixed_width', 'xml_dictionary']¶
- dictionary_source_ref: SourceRefId | None¶
- source_refs: SourceRefs¶
- legal_refs: LegalRefs¶
- records: tuple[ExportRecordDefinition, ...]¶