Source code for cadrumo.application.ledger.readiness_query
"""Readiness issues joined to the ledger facts that explain them.A preflight issue names a transaction and a reason. On its own that tells anoperator a row is not ready without telling them why, so the facts a readerneeds to act -- the classification and the four tax fields a deductible row mustcarry -- are joined on here. Choosing WHICH facts accompany an issue is adiagnostic decision, not formatting, and it had been made inside the CLI statusverb where no second surface could reach it.The join can miss. A preflight report and the catalogue are two reads, so anissue can name a transaction the catalogue no longer holds. The adapter droppedthose silently, which makes the issues an operator sees fewer than the countreported beside them with nothing saying so. Here the issue survives with``transaction_present`` false and its facts absent, because a readiness problemwhose row has vanished is a stronger signal than one whose row is merelyincomplete -- not a reason to say nothing."""from__future__importannotationsfromdecimalimportDecimalfromtypingimportTYPE_CHECKINGfrompydanticimportBaseModelfrom...core.modelsimportSTRICT_FROZEN_CONFIGfrom.preflightimportpreflight_ledger_tax_readinessifTYPE_CHECKING:from...core.periodimportPeriodfrom...domain.calculations.registry.authorityimportPinnedAuthorityOperationfrom.protocolsimportTransactionCatalogueCoCommitWriterProtocolfrom.usage_ratio_repositoryimportUsageRatioProfileLoader
[docs]classLedgerReadinessIssueV1(BaseModel):"""One readiness issue with the ledger facts that explain it. Every fact is optional because it is optional on the row: a deductible transaction missing its category is exactly the case this reports, so an absent value is the finding rather than a gap in the read. """model_config=STRICT_FROZEN_CONFIGtransaction_id:strreason:strdetail:strtransaction_present:boolbusiness_classification:str|None=Nonecategory_id:str|None=Nonetaxable_base:Decimal|None=Noneiva_rate:Decimal|None=Noneiva_amount:Decimal|None=None
[docs]defread_ledger_readiness(*,bucket_id:str,period:Period,transaction_repository:TransactionCatalogueCoCommitWriterProtocol,usage_ratio_profile_loader:UsageRatioProfileLoader,operation:PinnedAuthorityOperation,)->tuple[LedgerReadinessIssueV1,...]:"""Report this period's readiness issues with their explaining facts. Args: bucket_id: The owning profile bucket. period: The filing period to assess. transaction_repository: Explicit bucket-scoped catalogue port. usage_ratio_profile_loader: Profile-scoped declared ratio reader. operation: Caller-owned authority pin shared with the ledger workflow. Returns: Every issue the preflight raised, in report order, each carrying the row's facts when the row is still present. """report=preflight_ledger_tax_readiness(bucket_id=bucket_id,period=period,transaction_repository=transaction_repository,usage_ratio_profile_loader=usage_ratio_profile_loader,operation=operation,)from.actions_commonimportresolve_transaction_repositorycatalogue=resolve_transaction_repository(bucket_id=bucket_id,repository=transaction_repository).load()issues:list[LedgerReadinessIssueV1]=[]forissueinreport.issues:transaction=catalogue.get(issue.transaction_id)iftransactionisNone:issues.append(LedgerReadinessIssueV1(transaction_id=issue.transaction_id,reason=issue.reason.value,detail=issue.detail,transaction_present=False,))continueissues.append(LedgerReadinessIssueV1(transaction_id=issue.transaction_id,reason=issue.reason.value,detail=issue.detail,transaction_present=True,business_classification=transaction.business_classification.value,category_id=transaction.category_id,taxable_base=transaction.taxable_base,iva_rate=transaction.iva_rate,iva_amount=transaction.iva_amount,))returntuple(issues)