cadrumo.adapters.outbound.aeat.sede.filed_observation_persistence module

Concrete adapters for the filed-observation application ports.

The live filed-history service owns only protocols. This module is the outer binding for those protocols: it joins the existing Sede parser and observation store to the encrypted calculation, filing, IVA-history, event, and baseline repositories and the filing-chain reconciliation. Adapter failures are translated at this boundary so an application caller never has to know a Sede or secure-object exception type.

Core types: ModeloRecord, SecureObjectRepository.

class FiledObservationParserAdapter(*args, **kwargs)[source]

Bases: FiledObservationParserPort

Adapt receipt parsing and Sede CSV extraction to application types.

parse_justificante(body)[source]

Parse receipt bytes without creating a plaintext temporary file.

Return type:

Justificante

Parameters:

body (bytes)

csv_from_source_url(source_url)[source]

Extract the independent AEAT CSV witness from a source URL.

Return type:

str

Parameters:

source_url (str)

class FiledDeclarationTransformationAdapter(*, operation)[source]

Bases: FiledDeclarationTransformationPort

Adapt Sede observation projections to registry-grounded application ports.

Parameters:

operation (PinnedAuthorityOperation)

registry_observation(observation)[source]

Build the registry-grounded numeric projection.

Return type:

RegistryModeloObservation

Parameters:

observation (FiledObservationProtocol)

non_numeric_casillas(observation)[source]

Return non-numeric observed casillas for the operator projection.

Return type:

Sequence[FiledObservationSkipProtocol]

Parameters:

observation (FiledObservationProtocol)

class FiledObservationStoreAdapter(*, root, objects)[source]

Bases: FiledObservationPersistencePort

Adapt the encrypted Sede observation store to the application port.

Parameters:
persist_observation(observation)[source]

Persist one encrypted observation manifest.

Return type:

Path

Parameters:

observation (FiledObservationProtocol)

persist_artefact(observation_key, artefact, body)[source]

Persist one encrypted artefact and return its storage reference.

Return type:

FiledObservationArtefactProtocol

Parameters:
load_artefact(storage_ref)[source]

Load and verify one encrypted artefact by its content address.

Return type:

bytes

Parameters:

storage_ref (str)

class CalculationObservationRepositoryAdapter(*, repository)[source]

Bases: FiledCalculationObservationRepositoryPort

Adapt the encrypted calculation-observation repository.

Parameters:

repository (CalculationObservationRepository)

load_observation(modelo, period)[source]

Load one existing calculation-observation envelope.

Return type:

ObservationEnvelopePayload | None

Parameters:
prepare_observation_envelope(observation, *, source_kind, stamped_revision_id, captured_at=None, source_metadata=None, source_headers=())[source]

Prepare one validated calculation-observation envelope.

Return type:

ObservationEnvelopePayload

Parameters:
save(payload)[source]

Persist one prepared calculation-observation envelope.

Return type:

None

Parameters:

payload (ObservationEnvelopePayload)

class IvaHistoryRepositoryAdapter(*, repository)[source]

Bases: FiledIvaHistoryRepositoryPort

Adapt the encrypted IVA compensation-history repository.

Parameters:

repository (IvaCompensationHistoryRepository)

load_period(period)[source]

Reload one persisted IVA history period.

Return type:

IvaCompensationPeriodState | None

Parameters:

period (Period)

class IvaObservationPersistenceAdapter(*args, **kwargs)[source]

Bases: FiledIvaObservationPersistencePort

Adapt the canonical atomic Modelo 303/history co-commit operation.

persist(*, observation_repository, history_repository, envelope, taxpayer_nif, source_observation_key, expediente_id, status, source_artefact_sha256)[source]

Atomically persist the calculation envelope and IVA history state.

Return type:

IvaCompensationPeriodState

Parameters:
class JustificanteRepositoryAdapter(*, repository)[source]

Bases: JustificanteRepositoryProtocol

Adapt encrypted justificante metadata persistence.

Parameters:

repository (JustificanteRepository)

load(csv, /)[source]

Load one receipt by CSV.

Return type:

Justificante | None

Parameters:

csv (str)

save(justificante, /)[source]

Persist one parsed receipt.

Return type:

None

Parameters:

justificante (Justificante)

iter_justificantes()[source]

Yield all receipts after translating scan failures.

Return type:

Iterator[Justificante]

class FilingRepositoryAdapter(*, repository)[source]

Bases: ModeloRecordCatalogueRepositoryProtocol

Adapt encrypted modelo filing-record catalogue persistence.

Parameters:

repository (ModeloRecordCatalogueRepository)

property bucket_id: str | None

Return the repository’s bucket binding.

exists()[source]

Return whether the filing catalogue exists.

Return type:

bool

load()[source]

Load the filing catalogue.

Return type:

ModeloRecordCatalogue

load_revisioned()[source]

Load the filing catalogue and its revision marker.

Return type:

tuple[ModeloRecordCatalogue, str]

save(catalogue)[source]

Persist the filing catalogue.

Return type:

None

Parameters:

catalogue (ModeloRecordCatalogue)

mutate(mutation)[source]

Apply one guarded filing-catalogue mutation.

Return type:

ModeloRecordCatalogue

Parameters:

mutation (Callable[[ModeloRecordCatalogue], ModeloRecordCatalogue])

to_secure_object_write(catalogue, *, expected_revision_id=None)[source]

Prepare a filing-catalogue secure-object write.

Return type:

SecureObjectWrite

Parameters:
save_with_secure_object_writes(catalogue, extra_writes, *, expected_revision_id=None)[source]

Persist filing state and co-emitted writes atomically.

Return type:

None

Parameters:
class BucketEventRepositoryAdapter(*, repository)[source]

Bases: BucketEventHistoryRepositoryProtocol

Adapt encrypted bucket-event-history persistence.

Parameters:

repository (BucketEventHistoryRepository)

exists()[source]

Return whether the event catalogue exists.

Return type:

bool

load()[source]

Load the event catalogue.

Return type:

BucketEventHistoryCatalogue

save(catalogue)[source]

Persist the event catalogue.

Return type:

None

Parameters:

catalogue (BucketEventHistoryCatalogue)

to_secure_object_write(catalogue, *, expected_revision_id=None)[source]

Prepare an event-catalogue secure-object write.

Return type:

SecureObjectWrite

Parameters:
class FilingReconciliationAdapter(*, work_lifecycle_ports, calculation_repository, filing_repository, justificante_repository, observation_repository)[source]

Bases: FiledFilingReconciliationPort

Adapt the filing-chain reconciliation service with explicit repositories.

Parameters:
reconcile(entry, *, actor, clock)[source]

Reconcile one AEAT register entry under the bundled authority.

Return type:

FilingReconciliationResult

Parameters: