aeat.domain.calculations.registry._record_design_coverage module¶
Off-load-path record-design coverage and calculation-closure derivations.
calculation_closure_casilla_ids() and
calculation_closure_legal_refs() derive bounded closure projections from
a ModeloRevision; DisenoCoverageReport remains the advisory
full-Diseño inventory.
- class DerivedDisenoCasilla(segmento, number, casilla_id=None)[source]¶
Bases:
objectOne casilla derived from a registry closure or AEAT Diseño workbook.
segmentocarries the AEAT record-segment code (the workbook sheet name) for multi-segment modelos and isNonefor single-segment modelos.numberis the registry/display metadata under review.casilla_idis present only when the row came from a registry calculation closure; full-Diseño coverage rows may have no registry casilla yet and therefore leave it unset.
- calculation_closure_casilla_ids(revision, modelo_id)[source]¶
Return canonical casilla ids in a revision’s calculation closure.
The calculation closure is the set of casillas the cross-connecting calculation engine traverses within this modelo revision:
every
formula.target_casilla_idcasilla;every casilla referenced inside any
formula.expression, walked transitively via the runtime-graphexpression_casilla_refswalker;every casilla that declares a
formula(a computed endpoint) or abinding(a bound endpoint) — the engine-visible casillas;every verification-expectation operand casilla (
computed_casilla_idsand thereconciliation_total_casilla_idstargets);every within-modelo binding
source_casilla_ids/source_casilla_idselector casilla, and every within-modeloRelationDefinition.source_casilla_id.
A binding
source_casilla_ids/source_casilla_idselector — and aRelationDefinition.source_casilla_id— is excluded from this closure only when it is genuinely cross-modelo: when the selector explicitly names asource_modelothat differs frommodelo_id. A cross-modelo selector’ssource_casilla_ids/source_casilla_idname casillas on that foreign modelo, not on the modelo whose closure is being derived; the cross-modelo edge enters the current modelo through the bound casilla — the current-modelo casilla that declares the binding (or, for a relation,relation.target_binding) — which is already counted above as a binding endpoint. Folding a foreign-modelo casilla id into this closure would make the completeness gate demand it from the wrong modelo’s registry.A selector that omits
source_modeloor sets it equal tomodelo_idis a within-modelo selector: aprevious_filingself-binding or aprevious_periodself-relation names a casilla on the modelo being derived, so that casilla is a genuine closure member and is kept.References are not normalised through record-design metadata. A formula, binding, relation, or verification token must already be the canonical
casilla.idfor this revision. A reference token that matches no declared casilla id is kept verbatim so the manifest derivation and registry validation fail loudly on the unresolved canonical reference.- Parameters:
revision (
ModeloRevision) – TheModeloRevisionwhose formula and binding graph is walked to derive the closure.modelo_id (
str) – The AEAT modelo identifier used to exclude cross-modelo selector casillas from the closure.
- Return type:
frozenset[TypeAliasType]
- calculation_closure_record_design_metadata(revision, modelo_id)[source]¶
Return the
(segmento, number)metadata in a revision’s calculation closure.Metadata projection of
calculation_closure_casilla_ids(). The canonical closure never resolves throughcasilla.number; this function resolves each canonical id token to the declared casilla it names and keeps that casilla’s(segmento, number)record-design metadata.- Parameters:
revision (
ModeloRevision) – TheModeloRevisionwhose calculation closure to derive.modelo_id (
str) – Modelo identifier used to scope cross-modelo selectors; selectors whosesource_modelodiffers frommodelo_idare excluded from the closure.
- Return type:
The closure spans the same surface (formula targets, transitive formula-expression refs, formula/binding endpoint casillas, verification-expectation operands, and within-modelo binding / relation source casillas; only genuinely cross-modelo selectors — those whose
source_modelodiffers frommodelo_id— are excluded, seecalculation_closure_casilla_ids()). A reference token is resolved against the casillaidindex only:a token that matches a casilla
idresolves to that exact casilla’s metadata — this is how a multi-segment modelo’s formulas, which reference casillas by the segment-carrying compositeid(e.g.DP200014:00562), pin the closure to the correct record segment;a token that resolves to no declared casilla is kept as a bare
(None, token)metadata placeholder so a calculation that names a casilla the registry never declared still surfaces in the closure.
The calculation-completeness manifest is keyed on canonical
casilla.idand carries this metadata only for review and Diseño drift checks.
- calculation_closure_legal_refs(revision, modelo_id)[source]¶
Return legal references carried by a revision’s calculation closure.
Legal-ref projection of
calculation_closure_casilla_ids(). The completeness manifest is the reviewed ledger for the calculation closure, so its ownlegal_refsmust equal the refs carried by the closure casillas plus their endpoint formula/binding definitions and verification expectations.Unresolved closure tokens are skipped here because
derive_calculation_completeness_casillas()and the manifest drift gate already surface missing required casillas explicitly.- Parameters:
revision (
ModeloRevision) – TheModeloRevisionwhose calculation closure legal references are projected.modelo_id (
str) – Modelo identifier used to scope cross-modelo selectors.
- Return type:
frozenset[TypeAliasType]
- derive_calculation_completeness_casillas(revision, modelo_id, *, multi_segment, diseno_path=None)[source]¶
Return the calculation-completeness manifest casilla set for a revision.
Derives the modelo’s calculation closure (
calculation_closure_casilla_ids()) and carries each closure casilla’s own registry(segmento, number)metadata. The closure bounds the manifest to exactly the casillas the cross-connecting calculation engine traverses; the registry’s canonicalcasilla.id— not a five-digit AEAT Diseño tag — names each manifest entry.This derivation is vocabulary-agnostic. Only Modelo 200’s registry casilla
number\ s are genuine five-digit AEAT Diseño tags; the other calculation-bearing modelos identify casillas by semantic slug (iva.cuota-devengada-total) or short ordinal (01-19). The manifest is therefore derived from the modelo’s calculation surface keyed on canonicalcasilla.idand carrying the registry metadata each closure casilla declares, so it can be authored for any calculation-bearing modelo regardless of its casilla vocabulary.For a
multi_segmentmodelo the result is segment-aware. A multi-segment modelo reuses the same casilla number across distinct record segments and its formulas reference casillas by the segment-carrying compositeid, so the metadata-preserving closure (calculation_closure_record_design_metadata()) already pins each closure casilla to the exact record segment the calculation surface uses. Whendiseno_pathis supplied each segment-scoped metadata pair is additionally verified against the AEAT Diseño de Registros: the Diseño remains authoritative on which record segment carries a number, and a pinned(segmento, number)absent from the Diseño is a derivation error.For a single-segment modelo
segmentois left unset and the closure casilla’s registrynumberalone carries the reviewed metadata; no Diseño is required because a single-segment modelo’s metadata is unambiguous without one.A closure reference that resolves to no declared casilla is omitted from the derived set — the calculation-completeness gate then fires on the missing required casilla when it compares the manifest to the declared casillas, which is the gate fulfilling its mission. The drift / coverage tests surface such gaps explicitly.
This is an off-load-path tool. When
diseno_pathis supplied it parses the multi-megabyte Diseño corpus and must never run on the snapshot-build path.- Parameters:
revision (
ModeloRevision) – TheModeloRevisionwhose calculation closure to derive into a manifest.modelo_id (
str) – Modelo identifier; cross-modelo selectors whosesource_modelodiffers frommodelo_idare excluded from the closure.multi_segment (
bool) – When True, the manifest is segment-aware and a casilla number repeated across distinct segments produces distinct manifest rows; when False, segment metadata is dropped from the manifest key.diseno_path (
Path|None) – Optional path to an AEAT Diseño workbook used to cross-check that every derived manifest casilla also appears on the published record design.
- Return type:
- Returns:
Tuple of
DerivedDisenoCasillarepresenting the calculation-completeness manifest.
- derive_diseno_coverage_casillas(path, *, multi_segment)[source]¶
Return
DerivedDisenoCasillaitems for the full casilla set declared by a Diseño.Runs read-only record-design extraction against the official AEAT Diseño de Registros source at
pathand collects every five-digit casilla tag embedded in the field descriptions, including the accounting-statement data-entry fields that feed no calculation.This is the input to the off-load-path advisory coverage report that inventories form-level data coverage. It is intentionally NOT a load-blocking gate: a modelo whose registry is not yet exhaustively backfilled against the full Diseño is reported as having a coverage gap, not failed at load. The load-blocking gate is keyed on the bounded calculation closure (
derive_calculation_completeness_casillas()) instead.For a
multi_segmentmodelo (e.g. Modelo 200, which reuses the same casilla number across distinct record segments) every casilla carries the workbook sheet name as itssegmento, so the same number under two segments yields two distinct metadata pairs. For a single-segment modelosegmentois left unset and the bare number alone identifies the casilla; a number that recurs across sheets of a single-segment Diseño collapses to one metadata pair, matching the bare-number registry behaviour.This is an off-load-path tool: it parses the multi-megabyte Diseño corpus and must never run on the snapshot-build path.
- Return type:
- Parameters:
- class DisenoCoverageReport(modelo_id, revision_id, diseno_casillas, covered_casillas, coverage_gap_casillas)[source]¶
Bases:
objectAn off-load-path advisory inventory of one revision’s Diseño coverage.
Compares a modelo revision’s declared casillas against the full AEAT Diseño de Registros casilla set — every five-digit casilla tag AEAT embeds in the form’s field descriptions, accounting-statement data-entry fields included.
This report is advisory: it is produced off the snapshot-build load path and never reds a load. A modelo whose registry is not yet exhaustively backfilled against the full Diseño is reported here as having a coverage gap, surfaced as information for follow-up authoring. The load-blocking gate is the bounded calculation-completeness gate, not this full-Diseño inventory — that Calculation-completeness is enforced at load; full-Diseño coverage is inventoried off-load-path as an advisory follow-up surface.
Fields:
modelo_id/revision_ididentify the revision inventoried.diseno_casillasis the full(segmento, number)set the Diseño declares.covered_casillasis the subset the registry also declares — the Diseño casillas the registry has backfilled.coverage_gap_casillasis the subset the Diseño declares that the registry does not — the advisory follow-up inventory.
- Parameters:
modelo_id (str)
revision_id (str)
diseno_casillas (tuple[DerivedDisenoCasilla, ...])
covered_casillas (tuple[DerivedDisenoCasilla, ...])
coverage_gap_casillas (tuple[DerivedDisenoCasilla, ...])
-
diseno_casillas:
tuple[DerivedDisenoCasilla,...]¶
-
covered_casillas:
tuple[DerivedDisenoCasilla,...]¶
-
coverage_gap_casillas:
tuple[DerivedDisenoCasilla,...]¶
- build_diseno_coverage_report(path, modelo_id, revision, *, multi_segment)[source]¶
Return the off-load-path full-Diseño coverage advisory report for a revision.
Extracts the full AEAT Diseño de Registros casilla set (
derive_diseno_coverage_casillas()) and compares it against the revision’s declared casillas, keyed on the(segmento, number)metadata. The result is aDisenoCoverageReportthat inventories how much of the form’s data surface the registry covers and which Diseño casillas remain to be authored.This is an advisory inventory, never a load gate. It is produced off the snapshot-build path — it parses the multi-megabyte Diseño corpus — and must never run on the load path. A coverage gap reported here does not fail any modelo: the load-blocking enforcement is the bounded calculation-completeness gate; calculation-completeness is enforced at load while full-Diseño coverage is inventoried off-load-path.
For a
multi_segmentmodelo the comparison is segment-aware: a Diseño casilla under segmentSis “covered” only when the registry declares a casilla with the same(S, number)metadata. For a single-segment modelosegmentois unset on both sides and the bare number alone identifies the casilla.- Parameters:
path (
Path) – Path to the official AEAT Diseño de Registros source file.modelo_id (
str) – The AEAT modelo identifier for the coverage report.revision (
ModeloRevision) – TheModeloRevisionwhose declared casillas are compared against the extracted Diseño casilla set.multi_segment (
bool) – Whether the modelo uses segment-qualified casilla ids.
- Return type: