cadrumo.application.filing.draft_review module¶
Draft approval persistence and stale-detection helpers.
Provides the approve_draft() / refresh_review_status() lifecycle on top of
domain.filing.schema.ModeloDraft and
domain.submission.models.ModeloDraftStatus, plus the deterministic
domain.filing.schema.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 receives the required
DraftReviewPorts
bundle. The executable composition root binds its concrete repositories before
the review lifecycle is invoked.
See also
application.filing.runtime.build_runtime_schema_provider()Builds the registry-backed schema provider whose casilla and formula surface participates in the approval basis.
application.review.source_adapters.drafts_pending()Emits stale filing approvals as high-severity review queue items.
domain.filing.schema.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.schema.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.
REVIEW_CHECKSUM_MISMATCH – The stored
review_checksumis not the checksum of the stored basis. Unlike every other reason here, this does not mean an upstream source moved – it means the persisted approval metadata is internally inconsistent, so the aggregate claim over the basis is false and the approval cannot be trusted even when every basis field still matches.
- 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¶
- REVIEW_CHECKSUM_MISMATCH¶
- compute_current_approval_basis(draft, *, bucket_id, schema_provider, ports, operation, 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 persisted
TransactionCatalogue, the 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, the prior observations, and the profile projection are read through the requiredportsbundle so stale detection is reproducible at refresh time without running the source mesh in the review layer.- Parameters:
draft (
ModeloDraft) – Thedomain.filing.schema.ModeloDraftwhose basis is being computed.bucket_id (
str) – Stable bucket identifier used to scope the supplied ports.schema_provider (
CasillaSchemaProvider) – The activedomain.filing.protocols.CasillaSchemaProvider.ports (
DraftReviewPorts) – Required application-owned persistence capabilities for the transaction, invoice, observation, and profile authorities.prior_filing_observations_fingerprint (
str|None) – Optional precomputed prior-filing digest. WhenNone, the digest is self-loaded from the bucket’sCalculationObservationRepositoryProtocol. Explicit values let callers reuse a digest they already computed.profile_activity_fingerprint (
str|None) – Optional precomputed taxpayer-profile digest. WhenNone, the digest is self-loaded from the bucket’sCommittedProfileRepository. Explicit values let callers reuse a digest they already computed.operation (
PinnedAuthorityOperation) – Caller-owned generation-pinned indexed authority operation.category_profiles (
Mapping[SpendingCategory,CategoryProfile] |None) – Optional override of the active category profile map.
- 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, ports, operation, 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.schema.ModeloDraftto inspect.bucket_id (
str) – Stable bucket identifier; forwarded tocompute_current_approval_basis().schema_provider (
CasillaSchemaProvider) – The activedomain.filing.protocols.CasillaSchemaProvider.ports (
DraftReviewPorts) – Required application-owned persistence capabilities forwarded tocompute_current_approval_basis().operation (
PinnedAuthorityOperation) – Caller-owned generation-pinned indexed authority operation.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, ports, operation, 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.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.protocols.CasillaSchemaProvider.ports (
DraftReviewPorts) – Required application-owned persistence capabilities forwarded tocompute_current_approval_basis().operation (
PinnedAuthorityOperation) – Caller-owned generation-pinned indexed authority operation.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.
- refresh_review_status(draft, *, bucket_id, schema_provider, ports, operation, 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.protocols.CasillaSchemaProvider.ports (
DraftReviewPorts) – Required application-owned persistence capabilities forwarded toapproval_stale_reasons().operation (
PinnedAuthorityOperation) – Caller-owned generation-pinned indexed authority operation.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.