cadrumo.application.modelo.data_inventory module

Data-inventory checklist composer for one modelo / filing-year / period.

Composes the registry-authoritative facts an operator needs before they can calculate a modelo: which manual casillas are required, which are optional, which are populated automatically from the bucket ledger, and which are populated from the active taxpayer profile (with a per-binding readiness flag so an unset profile fact — e.g. the home-office usage ratio — surfaces as an actionable gap rather than a silent blank downstream).

This module owns the read-only composition over (the generation-pinned indexed registry operation) (the registry snapshot for the casilla/binding declarations) and profile_resolvable_binding_ids() (the profile-fact resolution already used by the bindings list --missing surface), so the CLI requires command stays a thin projection layer. No new aggregation path is introduced: the same registry snapshot and profile-binding resolver the calculate path uses are read, not re-derived.

See also

required_input_casilla_ids_for_revision()

Sibling helper returning only the bare required/optional id tuples (used by amendment completeness checks); this module composes the richer operator-facing checklist over the same snapshot.

profile_resolvable_binding_ids()

Profile-fact binding resolver reused here to flag missing coefficients.

Core types: ModeloRevision.

class DataInventoryCasilla(casilla_id, number, label, legal_refs, source_refs, binding_id=None, binding_source=None)[source]

Bases: object

One casilla entry on a data-inventory checklist.

legal_refs and source_refs are mandatory and non-empty: regulatory grounding travels with a casilla all the way to the operator, so an entry that cannot say which provision establishes it has nothing to show and must not be built. The refs are copied from the registry CasillaDefinition, which already refuses an ungrounded casilla at registry build; enforcing it here too means the checklist type states the guarantee itself rather than inheriting it from wherever its fields happened to come from.

Parameters:
  • casilla_id (CasillaId)

  • number (str)

  • label (str)

  • legal_refs (tuple[LegalRefId, ...])

  • source_refs (tuple[SourceRefId, ...])

  • binding_id (BindingId | None)

  • binding_source (str | None)

casilla_id: TypeAliasType
number: str
label: str
legal_refs: tuple[TypeAliasType, ...]
source_refs: tuple[TypeAliasType, ...]
binding_id: TypeAliasType | None
binding_source: str | None
class DataInventoryChecklist(modelo, revision_id, filing_year, period, required_manual, optional_manual, ledger_derivable, profile_derivable, previous_filing, relation_prefill, live_observation, unbucketed_sources, unresolved_profile_bindings, unresolved_profile_keys, profile_checked)[source]

Bases: object

Composed “what data do I need” checklist for one modelo/year/period.

required_manual and optional_manual are the casillas an operator must (or may) hand-enter. ledger_derivable are casillas the ledger aggregation mesh populates automatically once the relevant transactions are imported and classified — the operator imports these rather than typing them. profile_derivable are casillas populated from the active taxpayer profile (coefficients such as the home-office usage ratio). previous_filing and relation_prefill expose the two distinct cross-filing channels. live_observation contains bucket-local observation, register, and invoice-backed sources; it does not imply a remote AEAT query. unbucketed_sources preserves any remaining declared binding pair for an advisory instead of silently dropping it.

unresolved_profile_bindings names the subset of those bindings the active profile has not yet supplied a fact for, so the checklist can warn the operator before they calculate and hit a missing-binding refusal.

Parameters:
modelo: str
revision_id: TypeAliasType
filing_year: int
period: str
required_manual: tuple[DataInventoryCasilla, ...]
optional_manual: tuple[DataInventoryCasilla, ...]
ledger_derivable: tuple[DataInventoryCasilla, ...]
profile_derivable: tuple[DataInventoryCasilla, ...]
previous_filing: tuple[DataInventoryCasilla, ...]
relation_prefill: tuple[DataInventoryCasilla, ...]
live_observation: tuple[DataInventoryCasilla, ...]
unbucketed_sources: tuple[DataInventoryCasilla, ...]
unresolved_profile_bindings: tuple[TypeAliasType, ...]
unresolved_profile_keys: tuple[str, ...]

The profile keys those unresolved bindings consume, in binding order and de-duplicated. Carried alongside the binding ids because the operator needs to know WHICH PROFILE FACT to supply, and a binding id names the registry’s internal consumer of that fact rather than the fact itself.

profile_checked: bool
data_inventory_checklist(*, modelo, filing_year, period, bucket_id, operation)[source]

Compose the data-inventory checklist for one modelo / year / period.

Reads the resolved RegistrySnapshot for (modelo, filing_year, period) and classifies every casilla:

  • input_kind == MANUAL casillas split into required_manual / optional_manual by their required flag.

  • input_kind == BOUND casillas are classified by their binding’s BindingSourceKind: ledger-aggregation sources become ledger_derivable; profile sources become profile_derivable; prior-filing carries, relation prefills, and bucket-local observation/register/invoice sources have their own buckets. Source kinds outside those explicit buckets remain visible in unbucketed_sources so taxonomy growth cannot silently disappear.

  • COMPUTED and INFORMATIONAL casillas need no source data and are omitted.

When bucket_id names an active profile, profile_derivable bindings are cross-checked against profile_resolvable_binding_ids() and any binding the profile has not yet resolved is surfaced in unresolved_profile_bindings — the coefficient-missing warning the issue calls for (e.g. an unset home-office ratio). profile_checked is False when no bucket_id was supplied or the check could not run; callers should not read an empty unresolved_profile_bindings as “all clear” in that case.

Raises:

RegistrySnapshotError – When the registry has no revision covering (modelo, filing_year, period).

Return type:

DataInventoryChecklist

Returns:

A DataInventoryChecklist.

Parameters: