Source code for cadrumo.application.live.justificante_ports
"""Application ports for live justificante capture.The capture workflow names only the values it needs from Sede and from localstorage. Adapter and entrypoint code implement these ports; this module ownsno transport, browser, parser, or secure-store construction."""from__future__importannotationsfromcollections.abcimportAwaitable,Callable,SequencefromdataclassesimportdataclassfromdatetimeimportdatetimefromtypingimportProtocolfrom...core.periodimportPeriodfrom...domain.justificante.schemaimportJustificantefrom...domain.modelos.filing_recordimportModeloRecordCataloguefrom.filed_observation_portsimportFiledFilingReconciliationPort
[docs]@dataclass(frozen=True,slots=True)classJustificanteDeclaration:"""Period-bearing declaration data used to select an expediente."""modelo:strperiod:Periodexpediente_id:strestado:strpresented_at:datetime
[docs]@dataclass(frozen=True,slots=True)classJustificanteExpediente:"""Minimal Sede procedure-tree entry needed to fetch a receipt."""expediente_id:str
[docs]@dataclass(frozen=True,slots=True)classCapturedJustificante:"""Authenticated receipt bytes and Sede references returned by a live read."""expediente_id:strcsv:strpdf_bytes:bytespdf_sha256:str
[docs]classJustificanteSnapshotPersistencePort(Protocol):"""Bucket-bound encrypted persistence for capture snapshots."""@propertydefbucket_id(self)->str:"""Return the bucket identity that owns these snapshots."""...
[docs]defexists(self,snapshot_id:str)->bool:"""Return whether a snapshot identifier is persisted."""...
[docs]defload(self,snapshot_id:str)->object:"""Load one persisted snapshot by identifier."""...
[docs]deflist_snapshots(self)->Sequence[object]:"""Return the persisted snapshots visible to this bucket."""...
[docs]defresolve(self,snapshot_id:str)->object:"""Resolve one snapshot identifier to its persisted record."""...
[docs]defsave(self,snapshot:object)->None:"""Persist one capture snapshot through the encrypted store."""...
[docs]classJustificanteMetadataPort(Protocol):"""Durable metadata registration for a parsed receipt."""
[docs]classJustificanteFilingPort(Protocol):"""Load and save the local filing catalogue."""
[docs]defload(self)->ModeloRecordCatalogue:"""Load the local filing catalogue."""...
[docs]defsave(self,catalogue:ModeloRecordCatalogue)->None:"""Persist the local filing catalogue."""...
[docs]@dataclass(frozen=True,slots=True)classJustificanteRegistrationPorts:"""Application-owned local persistence dependencies for receipt enrolment."""parse_pdf:Callable[[bytes],Justificante]metadata:JustificanteMetadataPortfiling:JustificanteFilingPortfiling_reconciliation:FiledFilingReconciliationPort
[docs]classJustificanteLiveReadPort(Protocol):"""Read the declaration register, procedure tree, and selected receipt."""
[docs]asyncdefdeclarations_and_expedientes(self,*,modelo:str,year:int,)->tuple[Sequence[JustificanteDeclaration],Sequence[JustificanteExpediente]]:"""Read declarations and their matching procedure-tree entries."""...
[docs]asyncdefcapture(self,*,expediente_id:str)->CapturedJustificante:"""Capture one authenticated receipt for an expediente."""...
[docs]defverify(self,csv:str,*,browser:object|None=None,browser_session_factory:Callable[[],object]|None=None,)->Awaitable[bool]:"""Verify a receipt CSV through the live cotejo operation."""...