aeat.application.modelo._selectors module¶
Selector policy for operator-facing modelo work targets.
Visible modelo/year/period input is normalized into a
ModeloWorkSelectorRequest and resolved to a
ModeloWorkResolution over active
aeat.domain.modelos.WorkUnit records. Revision selectors
then load persisted CalculationRevision rows and return a
ModeloCalculationRevisionSelection for current, latest draft, latest
verified, filed, or explicit-id picks.
The selector boundary implements the accepted visible-target addressing policy: the common operator target is active bucket/profile plus modelo, filing year, and period; raw work-unit and calculation-revision ids remain exact-addressing escape hatches. An explicit work-unit id is validated against any natural-key flags supplied beside it, discarded work units are ignored by default, and an ambiguous visible target refuses with candidate guidance instead of guessing.
Command-specific revision defaults stay here rather than in CLI modules: verification selects the current draft, filing selects the current verified-complete revision, and export prefers the current filed revision before falling back to an unambiguous verified-complete revision.
- class ModeloWorkSelectorState(*values)[source]¶
Bases:
StrEnumResolution state for a visible modelo filing target.
- ABSENT¶
- RESOLVED¶
- class ModeloCalculationRevisionSelector(*values)[source]¶
Bases:
StrEnumClosed selector set for calculation revisions under a work unit.
- CURRENT¶
- LATEST_DRAFT¶
- LATEST_VERIFIED¶
- FILED¶
- EXPLICIT¶
- class ModeloVerifySelector(*values)[source]¶
Bases:
StrEnumDraft-reachable selector subset accepted by
modelo work verify.verify_modelo_revisionrefuses any revision not in stateBORRADOR, so the only selectors that can resolve to a verifiable revision are the ones that reach a draft:current(when the current revision is still a draft),latest-draft, andexplicit(an explicitly-named draft revision id). The post-draft selectorslatest-verifiedandfiledon the fullModeloCalculationRevisionSelectorname states verify rejects, so advertising them on the verify command is an advertised-but-impossible combination (audit2026-06-10-cli-operator-surface-auditF5(d), decision D5). This narrowed enum is what the verify--selectoption advertises; other commands keep the full selector enum.- CURRENT¶
- LATEST_DRAFT¶
- EXPLICIT¶
- to_calculation_revision_selector()[source]¶
Map a verify selector to its
ModeloCalculationRevisionSelectormember.- Return type:
- exception ModeloWorkSelectorError(message=None, *, context=None, suggestion=None, translated_message=None)[source]¶
Bases:
ModeloErrorBase error for modelo work selector refusals.
- Parameters:
- Return type:
None
- code: ClassVar[ErrorCode]¶
- exception ModeloWorkNoActiveBucketError(message=None, *, context=None, suggestion=None, translated_message=None)[source]¶
Bases:
ModeloWorkSelectorErrorRaised when a selector requires the active bucket but none is selected.
- Parameters:
- Return type:
None
- code: ClassVar[ErrorCode]¶
- exception ModeloWorkUnitNotFoundError(message=None, *, context=None, suggestion=None, translated_message=None)[source]¶
Bases:
ModeloWorkSelectorError,KeyErrorRaised when an explicit work-unit id does not exist.
- Parameters:
- Return type:
None
- code: ClassVar[ErrorCode]¶
- exception ModeloWorkSelectorContradictionError(message=None, *, context=None, suggestion=None, translated_message=None)[source]¶
Bases:
ModeloWorkSelectorError,ValueErrorRaised when explicit id and natural-key flags address different work.
- Parameters:
- Return type:
None
- code: ClassVar[ErrorCode]¶
- exception ModeloWorkVisibleTargetAmbiguousError(candidates)[source]¶
Bases:
ModeloWorkSelectorErrorRaised when a visible target matches multiple active work units.
- Parameters:
candidates (tuple[ModeloWorkUnitCandidate, ...])
- Return type:
None
- code: ClassVar[ErrorCode]¶
- exception ModeloWorkRevisionConflictError(*, requested_revision_id, existing)[source]¶
Bases:
ModeloWorkSelectorErrorRaised when the requested registry revision conflicts with active work.
- Parameters:
requested_revision_id (str)
existing (ModeloWorkUnitCandidate)
- Return type:
None
- code: ClassVar[ErrorCode]¶
- exception ModeloCalculationRevisionSelectorError(message=None, *, context=None, suggestion=None, translated_message=None)[source]¶
Bases:
ModeloErrorBase error for calculation-revision selector refusals.
- Parameters:
- Return type:
None
- code: ClassVar[ErrorCode]¶
- exception ModeloCalculationRevisionSelectorNotFoundError(message=None, *, context=None, suggestion=None, translated_message=None)[source]¶
Bases:
ModeloCalculationRevisionSelectorError,KeyErrorRaised when a requested calculation revision cannot be selected.
- Parameters:
- Return type:
None
- code: ClassVar[ErrorCode]¶
- exception ModeloCalculationRevisionSelectorStateError(message=None, *, context=None, suggestion=None, translated_message=None)[source]¶
Bases:
ModeloCalculationRevisionSelectorErrorRaised when a command-specific selector finds a revision in the wrong state.
- Parameters:
- Return type:
None
- code: ClassVar[ErrorCode]¶
- exception ModeloCalculationRevisionSelectorAmbiguousError(candidates)[source]¶
Bases:
ModeloCalculationRevisionSelectorErrorRaised when a default revision selector would have to guess.
- Parameters:
candidates (tuple[ModeloCalculationRevisionCandidate, ...])
- Return type:
None
- code: ClassVar[ErrorCode]¶
- class ModeloWorkSelectorRequest(**data)[source]¶
Bases:
BaseModelOperator-facing modelo work selector.
bucket_idis optional so callers can address the active profile bucket by default.work_unit_idis the exact-addressing escape hatch; when present, any natural-key flags supplied alongside it are validated against the loaded work unit.- Parameters:
modelo (ModeloCode | None)
filing_year (Annotated[int, FieldInfo(annotation=NoneType, required=True, metadata=[Ge(ge=2000), Le(le=2099)])] | None)
period (Period | None)
revision_id (Annotated[str, StringConstraints(strip_whitespace=True, to_upper=None, to_lower=None, strict=None, min_length=1, max_length=128, pattern=None, ascii_only=None)] | None)
bucket_id (Annotated[str, StringConstraints(strip_whitespace=True, to_upper=None, to_lower=None, strict=None, min_length=1, max_length=128, pattern=None, ascii_only=None)] | None)
work_unit_id (Annotated[str, StringConstraints(strip_whitespace=True, to_upper=None, to_lower=None, strict=None, min_length=64, max_length=64, pattern=^[0-9a-f]{64}$, ascii_only=None)] | None)
- modelo: ModeloCode | None¶
- filing_year: Annotated[int, Field(ge=2000, le=2099)] | None¶
- period: Period | None¶
- revision_id: _RevisionId | None¶
- bucket_id: _BucketId | None¶
- work_unit_id: WorkUnitId | None¶
- class ModeloWorkUnitCandidate(**data)[source]¶
Bases:
BaseModelHuman-readable candidate metadata for selector guidance.
- Parameters:
work_unit_id (Annotated[str, StringConstraints(strip_whitespace=True, to_upper=None, to_lower=None, strict=None, min_length=64, max_length=64, pattern=^[0-9a-f]{64}$, ascii_only=None)])
short_work_unit_id (str)
bucket_id (Annotated[str, StringConstraints(strip_whitespace=True, to_upper=None, to_lower=None, strict=None, min_length=1, max_length=128, pattern=None, ascii_only=None)])
modelo (ModeloCode)
filing_year (Annotated[int, FieldInfo(annotation=NoneType, required=True, metadata=[Ge(ge=2000), Le(le=2099)])])
period (Period)
revision_id (Annotated[str, StringConstraints(strip_whitespace=True, to_upper=None, to_lower=None, strict=None, min_length=1, max_length=128, pattern=None, ascii_only=None)])
state (WorkUnitState)
current_calculation_revision_id (str | None)
filed_calculation_revision_id (str | None)
current_filing_record_id (str | None)
created_at (str)
updated_at (str)
- work_unit_id: WorkUnitId¶
- short_work_unit_id: str¶
- bucket_id: _BucketId¶
- modelo: ModeloCode¶
- filing_year: Annotated[int, Field(ge=2000, le=2099)]¶
- period: Period¶
- revision_id: _RevisionId¶
- state: WorkUnitState¶
- current_calculation_revision_id: str | None¶
- filed_calculation_revision_id: str | None¶
- current_filing_record_id: str | None¶
- created_at: str¶
- updated_at: str¶
- classmethod from_work_unit(unit)[source]¶
Project a work unit into a
ModeloWorkUnitCandidateselector guidance record.- Return type:
- Parameters:
unit (WorkUnit)
- class ModeloCalculationRevisionCandidate(**data)[source]¶
Bases:
BaseModelHuman-readable calculation revision metadata for selector guidance.
- Parameters:
calculation_revision_id (Annotated[str, StringConstraints(strip_whitespace=True, to_upper=None, to_lower=None, strict=None, min_length=64, max_length=64, pattern=^[0-9a-f]{64}$, ascii_only=None)])
short_calculation_revision_id (str)
work_unit_id (Annotated[str, StringConstraints(strip_whitespace=True, to_upper=None, to_lower=None, strict=None, min_length=64, max_length=64, pattern=^[0-9a-f]{64}$, ascii_only=None)])
state (CalculationRevisionState)
created_at (str)
updated_at (str)
verified_at (str | None)
filed_at (str | None)
- calculation_revision_id: CalculationRevisionId¶
- short_calculation_revision_id: str¶
- work_unit_id: WorkUnitId¶
- state: CalculationRevisionState¶
- created_at: str¶
- updated_at: str¶
- verified_at: str | None¶
- filed_at: str | None¶
- classmethod from_revision(revision)[source]¶
Project a
CalculationRevisioninto aModeloCalculationRevisionCandidate.- Return type:
- Parameters:
revision (CalculationRevision)
- class ModeloCalculationRevisionSelection(**data)[source]¶
Bases:
BaseModelResolved calculation revision selection under a work unit.
- Parameters:
selector (ModeloCalculationRevisionSelector)
work_unit_id (Annotated[str, StringConstraints(strip_whitespace=True, to_upper=None, to_lower=None, strict=None, min_length=64, max_length=64, pattern=^[0-9a-f]{64}$, ascii_only=None)])
revision (CalculationRevision)
candidates (tuple[ModeloCalculationRevisionCandidate, ...])
- selector: ModeloCalculationRevisionSelector¶
- work_unit_id: WorkUnitId¶
- revision: CalculationRevision¶
- candidates: tuple[ModeloCalculationRevisionCandidate, ...]¶
- class ModeloWorkResolution(**data)[source]¶
Bases:
BaseModelResolved selector outcome for a visible modelo filing target.
- Parameters:
state (ModeloWorkSelectorState)
bucket_id (Annotated[str, StringConstraints(strip_whitespace=True, to_upper=None, to_lower=None, strict=None, min_length=1, max_length=128, pattern=None, ascii_only=None)])
modelo (ModeloCode | None)
filing_year (Annotated[int, FieldInfo(annotation=NoneType, required=True, metadata=[Ge(ge=2000), Le(le=2099)])] | None)
period (Period | None)
requested_revision_id (Annotated[str, StringConstraints(strip_whitespace=True, to_upper=None, to_lower=None, strict=None, min_length=1, max_length=128, pattern=None, ascii_only=None)] | None)
work_unit (WorkUnit | None)
candidates (tuple[ModeloWorkUnitCandidate, ...])
- state: ModeloWorkSelectorState¶
- bucket_id: _BucketId¶
- modelo: ModeloCode | None¶
- filing_year: Annotated[int, Field(ge=2000, le=2099)] | None¶
- period: Period | None¶
- requested_revision_id: _RevisionId | None¶
- work_unit: WorkUnit | None¶
- candidates: tuple[ModeloWorkUnitCandidate, ...]¶
- resolve_modelo_work_bucket(request)[source]¶
Resolve the selector bucket from an explicit id or the active profile.
- Return type:
- Parameters:
request (ModeloWorkSelectorRequest)
- visible_target_work_units(request, *, repository=None)[source]¶
Return active
aeat.domain.modelos.WorkUnitrecords matching the visible target.The visible target is bucket/modelo/filing-year/period only. Registry revision is intentionally not part of this lookup so a conflicting
revision_idcan be reported as a conflict against the existing active work unit instead of silently selecting or creating a second target.- Return type:
- Parameters:
request (ModeloWorkSelectorRequest)
repository (WorkUnitCatalogueRepositoryProtocol | None)
- resolve_modelo_work_unit(request, *, repository=None)[source]¶
Resolve one work unit and return a
ModeloWorkResolutionby exact id or visible target.The visible-target path deliberately searches by bucket/modelo/year/period before registry-revision exact targeting. That prevents a command from silently creating or selecting a second active work unit for the same filing.
- Return type:
- Parameters:
request (ModeloWorkSelectorRequest)
repository (WorkUnitCatalogueRepositoryProtocol | None)
- select_modelo_calculation_revision(work_unit, *, selector, calculation_revision_id=None, calculation_repository=None)[source]¶
Select one persisted calculation revision as
ModeloCalculationRevisionSelection.EXPLICITrequirescalculation_revision_idand verifies the revision belongs to the suppliedaeat.domain.modelos.WorkUnit. Non-explicit selectors resolve through the work unit’s current/filed pointers or by latest state, and refuse missing or mismatched state instead of falling back to another revision.- Return type:
- Parameters:
work_unit (WorkUnit)
selector (ModeloCalculationRevisionSelector)
calculation_revision_id (str | None)
calculation_repository (CalculationRevisionCatalogueRepositoryProtocol | None)
- resolve_modelo_calculation_revision_pick(work_unit, *, selector=ModeloCalculationRevisionSelector.CURRENT, calculation_revision_id=None, default_for=None, calculation_repository=None)[source]¶
Resolve a command-specific
ModeloCalculationRevisionSelectionpick under one work unit.This is the application selector policy surface for commands that accept a natural work target plus a revision selector. It preserves the exact calculation-revision id escape hatch, while keeping command defaults explicit: verification consumes the current draft, filing consumes the current verified-complete revision, and export prefers filed/current verified revisions according to
select_exportable_revision.- Return type:
- Parameters:
work_unit (WorkUnit)
selector (ModeloCalculationRevisionSelector)
calculation_revision_id (str | None)
default_for (ModeloCalculationRevisionDefault | None)
calculation_repository (CalculationRevisionCatalogueRepositoryProtocol | None)
- select_current_draft_revision(work_unit, *, calculation_repository=None)[source]¶
Select the current draft revision as a
ModeloCalculationRevisionSelectionfor verification.- Return type:
- Parameters:
work_unit (WorkUnit)
calculation_repository (CalculationRevisionCatalogueRepositoryProtocol | None)
- select_current_verified_revision(work_unit, *, calculation_repository=None)[source]¶
Select the current verified-complete revision for filing.
Returns a
ModeloCalculationRevisionSelection.- Return type:
- Parameters:
work_unit (WorkUnit)
calculation_repository (CalculationRevisionCatalogueRepositoryProtocol | None)
- select_exportable_revision(work_unit, *, calculation_repository=None)[source]¶
Select the default exportable
ModeloCalculationRevisionSelectionfor a work unit.Preference order: 1. current filed pointer, when it points to a current filed revision; 2. current calculation pointer, when it is verified-complete; 3. one unambiguous verified-complete revision, only when no current draft conflicts.
- Return type:
- Parameters:
work_unit (WorkUnit)
calculation_repository (CalculationRevisionCatalogueRepositoryProtocol | None)