aeat.application.filing._review module¶
Draft approval persistence and stale-detection helpers.
Provides the approve_draft() / unapprove_draft() /
refresh_review_status() lifecycle on top of
domain.filing.ModeloDraft and
domain.submission.ModeloDraftStatus, plus the deterministic
domain.filing.ModeloApprovalBasis fingerprint pipeline that lets
approval_stale_reasons() detect when a
APROBADO draft has been
invalidated by upstream changes.
The compute_current_approval_basis() helper accepts optional
domain.transactions.TransactionCatalogue and category-profile
overrides. When the catalogue override is omitted, it loads the
TransactionCatalogue from the encrypted
secure-object backend through
TransactionCatalogueRepository.
See also
application.filing.build_runtime_schema_provider()Builds the registry-backed schema provider whose casilla and formula surface participates in the approval basis.
application.review.drafts_pending()Emits stale filing approvals as high-severity review queue items.
domain.filing.ModeloApprovalBasisPersisted digest bundle compared during stale detection.
- class ModeloApprovalStaleReason(*values)[source]¶
Bases:
StrEnumStable reason codes surfaced when a draft approval becomes stale.
- Variables:
APPROVAL_BASIS_VERSION_CHANGED – The
domain.filing.ModeloApprovalBasisschema version has been bumped since approval.DRAFT_PAYLOAD_CHANGED – The draft’s payload fingerprint (
draft_id) no longer matches the stored basis.DRAFT_REVIEW_CHANGED – The draft’s validation findings or machine status changed since approval.
TRANSACTION_CATALOGUE_CHANGED – Upstream classified transactions have been updated since approval.
INVOICE_CATALOGUE_CHANGED – Upstream issued/received invoices (a calculation source resolved through the source mesh) have been updated since approval.
PRIOR_FILING_OBSERVATIONS_CHANGED – Prior filed observations in the bucket (the previous_filing carry and relation fold-in source) have been updated since approval.
PROFILE_ACTIVITY_CHANGED – The taxpayer profile facts that scope relation resolution (activity-start date, m111 no-retenciones attestations, declared income categories) have changed since approval.
CATEGORY_PROFILES_CHANGED – The fiscal category profile catalog has been edited since approval.
SCHEMA_FORMULA_CHANGED – The registry-backed casilla schema or formula set has changed since approval.
- APPROVAL_BASIS_VERSION_CHANGED¶
- DRAFT_PAYLOAD_CHANGED¶
- DRAFT_REVIEW_CHANGED¶
- TRANSACTION_CATALOGUE_CHANGED¶
- INVOICE_CATALOGUE_CHANGED¶
- PRIOR_FILING_OBSERVATIONS_CHANGED¶
- PROFILE_ACTIVITY_CHANGED¶
- CATEGORY_PROFILES_CHANGED¶
- SCHEMA_FORMULA_CHANGED¶
- compute_current_approval_basis(draft, *, bucket_id, schema_provider, transaction_catalogue=None, invoice_catalogue=None, prior_filing_observations_fingerprint=None, profile_activity_fingerprint=None, category_profiles=None)[source]¶
Return the
ModeloApprovalBasisdigests for current upstream state.The basis hashes the draft identity and validation surface, the supplied or persisted
TransactionCatalogue, the supplied or persistedInvoiceCatalogue(a calculation source resolved through the source mesh), the bucket’s prior filed observations (theprevious_filingcarry and relation fold-in source), the bucket’s taxpayer profile facts that scope relation resolution, the supplied or bundledCategoryProfilemapping, and the active registry schema/formula surface exposed byschema_provider.The invoice-catalogue, prior-filing-observations, and profile-activity digests make an
APROBADOdraft stale when its upstream invoices, prior filed values, or relation-scoping profile facts change, closing the gap left by fingerprinting only the ledger transaction catalogue. Like the transaction catalogue they are self-loaded frombucket_idso stale detection is reproducible at refresh time without running the source mesh in the review layer.- Parameters:
draft (
ModeloDraft) – Thedomain.filing.ModeloDraftwhose basis is being computed.bucket_id (
str) – Stable bucket identifier; used to load the persisted transaction and invoice catalogues and prior observations when no override is supplied.schema_provider (
CasillaSchemaProvider) – The activedomain.filing.CasillaSchemaProvider.transaction_catalogue (
TransactionCatalogue|None) – OptionalTransactionCatalogueoverride. WhenNone, the catalogue is loaded from the encryptedTransactionCatalogueRepository.invoice_catalogue (
InvoiceCatalogue|None) – OptionalInvoiceCatalogueoverride. WhenNone, the catalogue is loaded from the encryptedInvoiceCatalogueRepository.prior_filing_observations_fingerprint (
str|None) – Optional precomputed prior-filing digest. WhenNone, the digest is self-loaded from the bucket’sCalculationObservationRepository. A precomputed override (typicallyempty_prior_filing_observations_fingerprint()) lets a caller skip the bucket self-load for a deterministic basis without exposing the private stored-observation envelope type or routing to a non-active bucket.profile_activity_fingerprint (
str|None) – Optional precomputed taxpayer-profile digest. WhenNone, the digest is self-loaded from the bucket’sProfileRepository. A precomputed override (typicallyempty_profile_activity_fingerprint()) lets a caller skip the bucket self-load for a deterministic basis.category_profiles (
Mapping[SpendingCategory,CategoryProfile] |None) – Optional override of the active category profile map. Defaults to the bundled 2025 registry.
- Return type:
- Returns:
A freshly computed
ModeloApprovalBasis.
- compute_review_checksum(approval_basis)[source]¶
Return the canonical SHA-256 hex checksum for
approval_basis.- Parameters:
approval_basis (
ModeloApprovalBasis) – The basis to hash.- Return type:
- Returns:
Lowercase hex SHA-256 of the basis’s canonical JSON dump.
- approval_stale_reasons(draft, *, bucket_id, schema_provider, transaction_catalogue=None, invoice_catalogue=None, prior_filing_observations_fingerprint=None, profile_activity_fingerprint=None, category_profiles=None)[source]¶
Return the ordered stale reasons for
draft.The return value is empty when the draft has no approval metadata or when its stored approval basis still matches the freshly recomputed basis.
- Parameters:
draft (
ModeloDraft) – Thedomain.filing.ModeloDraftto inspect.bucket_id (
str) – Stable bucket identifier; forwarded tocompute_current_approval_basis().schema_provider (
CasillaSchemaProvider) – The activedomain.filing.CasillaSchemaProvider.transaction_catalogue (
TransactionCatalogue|None) – OptionalTransactionCatalogueoverride.invoice_catalogue (
InvoiceCatalogue|None) – OptionalInvoiceCatalogueoverride; forwarded tocompute_current_approval_basis().prior_filing_observations_fingerprint (
str|None) – Optional precomputed prior-filing digest override; forwarded tocompute_current_approval_basis().profile_activity_fingerprint (
str|None) – Optional precomputed taxpayer-profile digest override; forwarded tocompute_current_approval_basis().category_profiles (
Mapping[SpendingCategory,CategoryProfile] |None) – Optional category profile map override.
- Return type:
- Returns:
Tuple of
ModeloApprovalStaleReasonvalues in evaluation order; empty when the basis is fresh.
- approve_draft(draft, *, bucket_id, approved_by, schema_provider, transaction_catalogue=None, invoice_catalogue=None, prior_filing_observations_fingerprint=None, profile_activity_fingerprint=None, category_profiles=None, approved_at=None)[source]¶
Stamp approval metadata on
draftand promote it toAPROBADO.- Parameters:
draft (
ModeloDraft) – TheModeloDraftto approve. Must beModeloDraftStatus.LISTO_PARA_PRESENTAR. The optionaltransaction_catalogueis aTransactionCatalogueconsulted when computing the approval basis fingerprint; whenNoneit is loaded from the repository.bucket_id (
str) – Stable bucket identifier; forwarded tocompute_current_approval_basis().approved_by (
str) – Operator identifier; rejected when blank after stripping.schema_provider (
CasillaSchemaProvider) – The activedomain.filing.CasillaSchemaProvider.transaction_catalogue (
TransactionCatalogue|None) – Optional catalogue override.invoice_catalogue (
InvoiceCatalogue|None) – OptionalInvoiceCatalogueoverride; forwarded tocompute_current_approval_basis().prior_filing_observations_fingerprint (
str|None) – Optional precomputed prior-filing digest override; forwarded tocompute_current_approval_basis().profile_activity_fingerprint (
str|None) – Optional precomputed taxpayer-profile digest override; forwarded tocompute_current_approval_basis().category_profiles (
Mapping[SpendingCategory,CategoryProfile] |None) – Optional category profile map override.approved_at (
datetime|None) – Optional timestamp; defaults to the canonical clock helper.
- Return type:
- Returns:
A new
ModeloDraftwith approval metadata populated.- Raises:
ModeloDraftError – When
approved_byis blank or the draft is not inModeloDraftStatus.LISTO_PARA_PRESENTAR.
- unapprove_draft(draft, *, unapproved_at=None)[source]¶
Remove approval metadata and restore the machine validation status.
- Parameters:
draft (
ModeloDraft) – The draft to revert.unapproved_at (
datetime|None) – Optional timestamp; defaults to the canonical clock helper.
- Return type:
- Returns:
A new
ModeloDraftwith approval metadata cleared andstatusset to the validation status derived fromModeloDraft.findings.
- refresh_review_status(draft, *, bucket_id, schema_provider, transaction_catalogue=None, invoice_catalogue=None, prior_filing_observations_fingerprint=None, profile_activity_fingerprint=None, category_profiles=None, refreshed_at=None)[source]¶
Return
draftwith its approval status synchronised to current state.Downstream-status drafts (submitted / acknowledged / rejected / amended / cancelled) get any leftover approval metadata cleared so historical state cannot pretend to be current.
APROBADOdrafts transition toModeloDraftStatus.APROBACION_CADUCADAwhenapproval_stale_reasons()returns a non-empty tuple.- Parameters:
draft (
ModeloDraft) – The draft to refresh.bucket_id (
str) – Stable bucket identifier; forwarded toapproval_stale_reasons().schema_provider (
CasillaSchemaProvider) – The activedomain.filing.CasillaSchemaProvider.transaction_catalogue (
TransactionCatalogue|None) – OptionalTransactionCatalogueoverride used when computing the approval basis fingerprint.invoice_catalogue (
InvoiceCatalogue|None) – OptionalInvoiceCatalogueoverride; forwarded toapproval_stale_reasons().prior_filing_observations_fingerprint (
str|None) – Optional precomputed prior-filing digest override; forwarded toapproval_stale_reasons().profile_activity_fingerprint (
str|None) – Optional precomputed taxpayer-profile digest override; forwarded toapproval_stale_reasons().category_profiles (
Mapping[SpendingCategory,CategoryProfile] |None) – Optional category profile map override.refreshed_at (
datetime|None) – Optional timestamp; defaults to the canonical clock helper.
- Return type:
- Returns:
Either
draftunchanged (when no transition was needed) or a newModeloDraftwith the appropriate status update.
- describe_stale_reason(reason)[source]¶
Return a short localized explanation for
reason.- Parameters:
reason (
ModeloApprovalStaleReason) – TheModeloApprovalStaleReasonto describe.- Return type:
- Returns:
A localized phrase suitable for inline UI display.
- empty_prior_filing_observations_fingerprint()[source]¶
Return the digest of an empty prior-filing observation set.
A caller passes this to
compute_current_approval_basis()/approve_draft()to stamp a deterministic prior-filing digest without a bucket self-load (e.g. a test approving against a non-active/sentinel bucket with no prior observations), mirroring the empty-InvoiceCatalogueoverride the invoice fingerprint accepts.- Return type:
- empty_profile_activity_fingerprint()[source]¶
Return the digest of an absent taxpayer profile.
A caller passes this to
compute_current_approval_basis()/approve_draft()to stamp a deterministic profile digest without a bucket self-load (e.g. a test approving against a non-active/sentinel bucket with no profile), mirroring the empty overrides the other source fingerprints accept.- Return type: