Source code for cadrumo.application.ledger.review_advisories
"""One enumeration of everything a pending draft carries that blocks nothing.Two advisories exist over a draft --- the party-attribution one and thecountry-vocabulary one --- and each already knows how to say its own piece on theone-document surface. What neither could say is the thing a QUEUE needs: not theprose, but which KINDS this document carries, as a closed value a caller cancount, group and filter on.**The queue is where a non-blocking condition is either seen or lost.** Anoperator who never opens a document never meets an advisory attached only to``review view``, and the conditions on this axis are exactly the ones that reachthe record without stopping anything --- so "reachable from the detail view" isindistinguishable from unreachable for any document the operator had no reason toopen. Counting them on the queue row is what makes the reason to open it.**One authority, two consumers.** The queue and the one-document surface derivetheir kinds from this function rather than each classifying the advisoriesthemselves. A second derivation is a second answer: a queue that decides a draftcarries an attribution advisory while the detail view shows none sends theoperator to a document to look for something that is not there, and they stoptrusting the count.The kinds are counted, never merged. A code only a registry commit can close anda typo the operator fixes off the page are different work, and a singlehas-advisories flag would make an operator who can only do one of them unable tofind the documents they can act on.See Also: :func:`~application.ledger.party_attribution.party_attribution_advisory` The attribution advisory this projects. :func:`~application.ledger.country_vocabulary_advisory.country_vocabulary_advisory` The country-vocabulary advisory this projects. :class:`~core.confirmation_gate.ReviewAdvisoryKind` The closed axis the kinds are drawn from. :class:`~core.confirmation_gate.ConfirmationBlockReason` The blocking sibling axis, which answers the other half of a queue row."""from__future__importannotationsfromtypingimportTYPE_CHECKING,Finalfrom...core.confirmation_gateimportReviewAdvisoryKindfrom...domain.calculations.registry.authorityimportPinnedAuthorityOperationfrom...domain.iva.establishmentimportStatedCountryCodeStatusfrom...domain.iva.regime_legendimportresolve_regime_legendsfrom.country_vocabulary_advisoryimportcountry_vocabulary_advisoryfrom.invoice_extraction_authorityimportdefault_invoice_extraction_periodfrom.party_attributionimportparty_attribution_advisoryifTYPE_CHECKING:from.invoice_draft_recordsimportInvoiceDraft__all__=["review_advisory_kinds"]_COUNTRY_KIND:Final[dict[StatedCountryCodeStatus,ReviewAdvisoryKind]]={StatedCountryCodeStatus.UNASSIGNED:ReviewAdvisoryKind.COUNTRY_CODE_UNASSIGNED,StatedCountryCodeStatus.UNCATALOGUED:ReviewAdvisoryKind.COUNTRY_CODE_UNCATALOGUED,}"""Which advisory kind each reported country-code status is.A table rather than a branch because the mapping is the whole of thecorrespondence, and because the country advisory's own reported-status set isderived from the sentences it can say --- so a status that gains a sentence andno entry here is a kind the queue would silently stop counting."""
[docs]defreview_advisory_kinds(draft:InvoiceDraft,*,operation:PinnedAuthorityOperation,)->tuple[ReviewAdvisoryKind,...]:"""Return every non-blocking advisory kind one pending draft carries. Args: draft: The pending draft, exactly as the review surfaces hold it. operation: Caller-owned pinned authority operation retained by both advisory projections. Returns: The kinds present, each at most once and in a stable order: the attribution kind first, then the country kinds in the axis's own declaration order. Empty when the draft carries nothing advisory, which is an honest empty rather than a claim that the draft was not checked. Raises: IvaCatalogueError: When the bundled country vocabulary cannot be read, propagated on the terms the country advisory states --- a corrupt bundled table is a defect, not an unadvised draft. """kinds:list[ReviewAdvisoryKind]=[]if(party_attribution_advisory(draft,legends=resolve_regime_legends(operation=operation,effective_date=default_invoice_extraction_period().end_date,),operation=operation,)isnotNone):kinds.append(ReviewAdvisoryKind.PARTY_ATTRIBUTION)country=country_vocabulary_advisory(draft,operation=operation)ifcountryisnotNone:# Ordered by the status table rather than by the parties' document order:# a queue row whose kinds reorder because two parties swapped places is a# row an operator cannot compare against yesterday's.kinds.extend(kindforstatus,kindin_COUNTRY_KIND.items()ifcountry.by_status(status))returntuple(kinds)