"""Cross-module Protocols consumed by :mod:`application.filing`.Every upstream collaborator (modelo identity, casilla schemas, deadlineengine) is represented by a :class:`typing.Protocol` so the filingapplication package does not take a hard import on any sibling subpackage.Concrete implementations are wired at runtime by the entrypoint.These Protocols are intentionally minimal: they describe only theattributes :mod:`application.filing` actually consumes. They do notattempt to model the full surface of the upstream subpackages."""from__future__importannotationsfromcollections.abcimportMapping,SequencefromdatetimeimportdatefromdecimalimportDecimalfromtypingimportTYPE_CHECKING,Protocol,runtime_checkableifTYPE_CHECKING:# pragma: no cover — type-only importfromcadrumo.domain.calculations.registry.tax_id_formatimportSubjectTaxIdfrom...core.casilla_idimportCasillaIdfrom...core.periodimportPeriodfrom..calculations.registry.idsimportBindingId,FormulaId,LegalRefId,RelationId,SourceRefIdfrom..calculations.registry.schema_surfacesimportCasillaConstraints
[docs]@runtime_checkableclassCasillaSchema(Protocol):"""The minimal casilla schema surface consumed by builders. Attributes: casilla_id: Stable canonical ``casilla.id`` (e.g. ``"01"``). value_type: One of ``"decimal"``, ``"int"``, ``"str"``, ``"bool"``, ``"date"``. required: Whether the casilla must be present in a valid draft. formula: ID of the formula declared on this casilla, or ``None`` for literal casillas. formula_input_casilla_ids: Tuple of casilla IDs this casilla depends on. Empty for literal casillas. legal_refs: Regulatory citations grounding this casilla's definition (BOE / AEAT permalinks). source_refs: Source-material citations backing this casilla. constraints: Complete registry-owned numeric and text constraint contract, or ``None`` when the casilla is unconstrained. default: Default value used when the casilla is required and no input was supplied. """@propertydefcasilla_id(self)->CasillaId:"""Return the canonical ``casilla.id`` identifier."""...@propertydefvalue_type(self)->str:"""Return the casilla value-type tag."""...@propertydefrequired(self)->bool:"""Return whether the casilla must be present in a valid draft."""...@propertydefformula(self)->FormulaId|None:"""Return the formula ID, or ``None`` if this is a literal casilla."""...@propertydefformula_input_casilla_ids(self)->tuple[CasillaId,...]:"""Return the casilla IDs this casilla's formula depends on."""...@propertydeflegal_refs(self)->tuple[LegalRefId,...]:"""Return the regulatory citation IDs grounding this casilla."""...@propertydefsource_refs(self)->tuple[SourceRefId,...]:"""Return the source-material citation IDs for this casilla."""...@propertydefconstraints(self)->CasillaConstraints|None:"""Return the complete registry-owned constraint contract, if any."""...@propertydefdefault(self)->object|None:"""Return the default value used when no input is supplied."""...
[docs]@runtime_checkableclassCasillaCollection(Protocol):"""A collection of casilla schemas keyed by ID."""@propertydefschema_version(self)->str:"""Return the version of the underlying casilla DB."""...def__iter__(self)->object:# pragma: no cover - Protocol"""Iterate the collection."""...
[docs]defget(self,casilla_id:CasillaId)->CasillaSchema|None:"""Return the :class:`CasillaSchema` for ``casilla_id``, or ``None``."""...
[docs]defall(self)->Sequence[CasillaSchema]:"""Return every casilla schema in the collection. Returns: Sequence of every :class:`CasillaSchema` in the collection. """...
[docs]@runtime_checkableclassCasillaSchemaProvider(Protocol):"""Resolves a casilla collection for a given modelo."""
[docs]defget_collection(self,modelo:str)->CasillaCollection:"""Return the casilla collection for ``modelo``. Returns: The :class:`CasillaCollection` for the given modelo code. """...
[docs]@runtime_checkableclassDeadlineStatus(Protocol):"""Result of a deadline check for a (modelo, period) tuple."""@propertydefdue_date(self)->date:"""Return the AEAT-published due date."""...@propertydefis_overdue(self)->bool:"""Return ``True`` when the reference date is past ``due_date``."""...
[docs]@runtime_checkableclassDeadlineChecker(Protocol):"""Checks the filing deadline for a typed modelo period."""
[docs]defcheck(self,modelo:str,period:Period)->DeadlineStatus:"""Return the :class:`DeadlineStatus` for ``modelo`` and ``period``."""...
[docs]@runtime_checkableclassModeloProfile(Protocol):"""The taxpayer profile a draft is built for. Only the attributes :mod:`application.filing` actually consumes are declared here; downstream callers may use richer profile objects as long as they expose these attributes. """@propertydeftax_id(self)->SubjectTaxId:"""Return the taxpayer's NIF / NIE."""...@propertydefdisplay_name(self)->str:"""Return a short human-readable label for the taxpayer."""...
# The canonical input contract for casilla, binding, and relation values handed# to a filing builder. Mapping not dict so callers may pass any# read-only mapping. This is the single definition of ``ModeloInputs``# in the codebase; the application/workflow layer re-exports it.typeModeloInputScalar=str|int|Decimal|bool|date"""A single casilla, binding-row, or relation value accepted by the filing builder.Casilla inputs are canonical strings or decimals; year casillas (forexample modelo 390 casilla ``decl.ejercicio``) are plain integers, and registrybindings additionally accept booleans (``boolean`` data type) anddates (``text`` data type). ``build_draft`` parses and range-checksevery scalar against the registry casilla / binding schema."""typeModeloInputValue=ModeloInputScalar|Sequence[ModeloInputScalar]|Mapping[str,ModeloInputScalar]"""A filing-input value.Most casilla and binding inputs are a single :data:`ModeloInputScalar`.Repeating-row registry bindings (for example the modelo 131 repeatingactivity rows) accept a ``Sequence`` of row scalars, or a ``Mapping``of explicit row key to scalar."""typeModeloInputs=Mapping[CasillaId|BindingId|RelationId,ModeloInputValue]"""Read-only input mapping for casilla, binding, and relation values handed to afiling builder.Keys are casilla, binding, or relation IDs; values are :data:`ModeloInputValue`.A workflow inputs-provider that only ever yields flat scalars stillsatisfies this contract, so the workflow layer re-exports this symbolrather than defining a narrower divergent alias."""