cadrumo.application.review.source_adapters module

Read-only source projections for the unified review queue.

Each projection reads one application-owned source capability and emits a tuple of typed ReviewItem records. Projections are pure and stateless; they tolerate missing source records by returning an empty tuple. Severity is derived per source via a first-match-wins predicate table.

Persistence is supplied by the required DraftReviewPorts bundle. This module owns only source classification and typed review-item projection; the encrypted repositories remain outer composition concerns.

transactions_pending(*, ports, catalogue=None)[source]

Return one TransactionReviewItem per pending-review transaction.

catalogue is an optional TransactionCatalogue override; the repository is loaded when None.

Skips fully-classified rows (BUSINESS / PERSONAL / MIXED), rows explicitly skipped by rule (SKIPPED_BY_RULE), and rows the operator reviewed and deliberately excluded (REVIEWED_EXCLUDED) — those have a final disposition and do not want the operator’s attention.

Return type:

tuple[TransactionReviewItem, ...]

Parameters:
transactions_low_confidence(*, ports, threshold, catalogue=None)[source]

Return transactions whose decision confidence sits below a threshold.

Parameters:
  • ports (DraftReviewPorts) – Composed application capabilities for the profile to inspect.

  • threshold (Decimal) – Minimum acceptable confidence; transactions strictly below this value are included.

  • catalogue (TransactionCatalogue | None) – Optional TransactionCatalogue override; when None the catalogue is loaded from the composed repository.

Return type:

tuple[TransactionReviewItem, ...]

Surfaces every transaction whose classification_confidence is non-None and strictly less than the threshold, regardless of classification state. Transactions with None confidence are excluded because they have no claim to filter against.

Each element in the returned tuple is a TransactionReviewItem.

load_transactions(*, ports)[source]

Load the transaction catalogue through the composed application port.

Return type:

TransactionCatalogue | None

Parameters:

ports (DraftReviewPorts)

invoices_pending(*, ports, catalogue=None)[source]

Return InvoiceReviewItem records for unmatched / disputed / pending invoices.

Parameters:
Return type:

tuple[InvoiceReviewItem, ...]

load_invoices(*, ports)[source]

Load the invoice catalogue through the composed application port.

Return type:

InvoiceCatalogue | None

Parameters:

ports (DraftReviewPorts)

drafts_pending(settings, *, bucket_id, ports, operation, drafts=None)[source]

Return FindingReviewItem records for findings + unready drafts.

Parameters:
  • settings (Settings) – Active application settings.

  • bucket_id (str) – Stable bucket identifier for the draft repository to inspect.

  • ports (DraftReviewPorts) – Required encrypted persistence capabilities.

  • operation (PinnedAuthorityOperation) – Caller-owned generation-pinned indexed authority operation.

  • drafts (tuple[tuple[Path, ModeloDraft], ...] | None) – Optional pre-loaded sequence of (path, draft) pairs where each draft is a ModeloDraft; when None drafts are loaded from that bucket’s secure storage.

Return type:

tuple[FindingReviewItem, ...]

A draft whose profile_tax_id does not match the active profile’s tax id is not the active profile’s data and is skipped. Callers see only drafts owned by the active profile.

reviewed_against_current_state(draft, *, bucket_id, ports, operation)[source]

Return draft with an aged-out approval reported as aged out.

An approval is a claim about the inputs it was granted over, and the review queue is the surface whose job is to notice when that claim has stopped holding. Reading only the stored status cannot notice: an approved draft stays approved on disk however far the ledger, invoices, taxpayer profile or registry schema have moved underneath it, so the APROBACION_CADUCADA row this adapter already knows how to emit was unreachable and the queue reported nothing to do.

Only APROBADO drafts are recomputed. Every other status either has no approval basis to compare or is already downstream of approval, and the recomputation loads catalogues and a registry snapshot, which is not work to do for a draft that cannot be stale.

The refreshed draft is NOT written back. This module’s adapters are pure readers, and the verdict is derived state: freezing it into the store on a read would make the stored status depend on when someone happened to open the review queue.

Core types: ModeloDraft.

Return type:

tuple[ModeloDraft, tuple[ModeloApprovalStaleReason, ...]]

Parameters:
load_drafts(*, ports, operation)[source]

Iterate every persisted draft via the composed application capability.

Drafts are ciphertext-at-rest only. The helper returns the secure backend’s logical path marker alongside the typed payload so callers can identify the draft without consulting a plaintext draft directory.

Return type:

tuple[tuple[Path, ModeloDraft], ...]

Parameters: