cadrumo.application.modelo.external_import_actions module¶
External filing import actions for modelo baselines.
import_external_filing_evidence() turns
AEAT-attested external evidence into a presented
CalculationRevision plus current
ModeloRecord. Evidence-bearing imports validate the
referenced Justificante, stamp an
ExternalEvidence payload on the filing record,
supersede any prior current filing for the same target, and emit
modelo.filing.imported through
BucketEventHistoryRepositoryProtocol.
The imported record is the production baseline consumed by the amendment path.
It is intentionally distinct from a locally calculated and filed return:
external_evidence marks that the values came from official AEAT evidence,
while
external_filing_observations()
keeps the imported casilla values on the same registry-grounded
CasillaObservation contract as local
calculation revisions.
See also
filing_record_import():CLI surface that parses
filing-record importoptions and calls this service.amend_modelo_revision():Consumes the imported current
ModeloRecordas an amendment baseline.justificante:Receipt metadata store required by justificante-PDF and live-capture evidence kinds. CSV/XLSX register imports bind the source reference directly to the target work-unit coordinates instead of masquerading as a receipt.
reject_unknown_import_casillas():Resolves the registry snapshot and refuses noncanonical or undeclared imported casilla ids.
ExternalEvidence:Filing-record metadata that records the official evidence source.
Core types:
RegistrySnapshot.
- class ExternalFilingBaselineSource(modelo, filing_year, period, evidence_kind, evidence_reference_id, tax_id, casilla_lexicals, registry_revision_id=None)[source]¶
Bases:
objectOne source-only, casilla-complete external filing observation.
- Parameters:
-
evidence_kind:
ExternalEvidenceKind¶
- class ExternalFilingTarget(modelo, filing_year, period, registry_revision_id=None)[source]¶
Bases:
objectThe filing coordinate an external filing is recorded against.
- class ExternalFilingRevisionDraft(work_units, work_unit, revisions, revisions_revision_id, revision, evidence_reference_id, snapshot, canonical_values)[source]¶
Bases:
objectA validated, not yet persisted, presented revision for external filing content.
- Parameters:
work_units (WorkUnitCatalogue)
work_unit (WorkUnit)
revisions (CalculationRevisionCatalogue)
revisions_revision_id (str)
revision (CalculationRevision)
evidence_reference_id (str)
snapshot (RegistrySnapshot)
-
work_units:
WorkUnitCatalogue¶
-
revisions:
CalculationRevisionCatalogue¶
-
revision:
CalculationRevision¶
-
snapshot:
RegistrySnapshot¶
- resolve_external_filing_work_unit(target, *, bucket_id, actor, ports, operation, clock)[source]¶
Resolve the active work unit for
target, creating one when it is absent.- Return type:
- Parameters:
target (ExternalFilingTarget)
bucket_id (str)
actor (str)
ports (WorkLifecyclePorts)
operation (PinnedAuthorityOperation)
clock (datetime | None)
- external_filing_source_casillas(source)[source]¶
Return a source’s printed lexicals and their parsed values, once proven complete.
Refuses a source whose coordinate is inconsistent, whose lexicals are blank or non-numeric, or which omits a required numeric casilla of the registry revision.
- Raises:
ExternalModeloImportError – The source cannot be recorded as a baseline.
- Return type:
tuple[dict[TypeAliasType,str],dict[TypeAliasType,Decimal]]- Parameters:
source (ExternalFilingBaselineSource)
- import_external_filing_source(source, *, bucket_id, work_lifecycle_ports, operation, filing_instance_evidence=None, declared_kind=None, actor='aeat-import', calculation_repository=None, filing_repository=None, justificante_repository=None, observation_repository, clock=None)[source]¶
Resolve or create the target work unit and reconcile an amendable baseline.
Source lexical tokens are retained verbatim on the revision input snapshot; their independently parsed Decimal values feed the filing baseline.
- Return type:
- Parameters:
source (ExternalFilingBaselineSource)
bucket_id (str)
work_lifecycle_ports (WorkLifecyclePorts)
operation (PinnedAuthorityOperation)
filing_instance_evidence (FilingInstanceEvidence | None)
declared_kind (FilingDeclarationKind | None)
actor (str)
calculation_repository (CalculationRevisionCatalogueRepositoryProtocol | None)
filing_repository (ModeloRecordCatalogueRepositoryProtocol | None)
justificante_repository (JustificanteRepositoryProtocol | None)
observation_repository (CalculationObservationRepositoryProtocol)
clock (datetime | None)
- advance_external_filing_work_unit(catalogue, *, work_unit, revision_id, filing_record_id, now)[source]¶
Point one work unit at the co-committed external filing and its revision.
- Return type:
- Parameters:
catalogue (WorkUnitCatalogue)
work_unit (WorkUnit)
revision_id (CalculationRevisionId)
filing_record_id (str)
now (datetime)
- build_external_filing_observation_payload(*, evidence_kind, observation_repository, work_unit, revision, occurred_at, cleaned_reference, expected_tax_id, filing_record_id, source_headers)[source]¶
Build the CSV observation envelope when that evidence channel applies.
- Parameters:
evidence_kind (
ExternalEvidenceKind) – The import’s evidence channel; only an AEAT register CSV carries an observation envelope.observation_repository (
CalculationObservationRepositoryProtocol) – The store that prepares the envelope.work_unit (
WorkUnit) – The filing coordinate the import targets.revision (
CalculationRevision) – The importedCalculationRevision, whose observations the envelope carries.occurred_at (
datetime) – When the import was captured.cleaned_reference (
str) – The canonical register reference.expected_tax_id (
str|None) – The authenticated identity, when one is asserted.filing_record_id (
str) – The chain entry the envelope belongs to.source_headers (
tuple[ObservedHeaderFact,...]) – The register’s typed header facts.
- Return type:
- Returns:
The prepared envelope, or
Nonefor an evidence channel that has none.
- class ExternalFilingImportResult(filing_record, reconciliation)[source]¶
Bases:
objectThe chain entry an external filing import left in force, and the decision that placed it.
- Parameters:
filing_record (ModeloRecord)
reconciliation (FilingReconciliationResult)
-
filing_record:
ModeloRecord¶
-
reconciliation:
FilingReconciliationResult¶
- import_external_filing_evidence(*, work_unit_id, casilla_values, source_lexical_values_by_casilla_id=None, evidence_kind, evidence_reference_id, filing_instance_evidence=None, declared_kind=None, actor='aeat-import', work_unit_repository=None, calculation_repository=None, filing_repository=None, bucket_event_repository=None, justificante_repository=None, observation_repository, expected_tax_id=None, clock=None, source_headers=(), operation=None)[source]¶
Reconcile an externally filed return with its period’s filing chain.
The target
WorkUnitsupplies the bucket, modelo, filing year, period, and registry revision used to validate imported casillas. Justificante-bound evidence requires stored receipt metadata matching that target; CSV-register evidence binds the imported file itself to the target, andsource_headerscarries the register’s typed header facts, such as the Modelo 303 declaration type its carry ingress requires.The values go through
reconcile_aeat_register_entry(): a matching pending local filing is confirmed, a disagreeing one is superseded by the imported content, and otherwise the imported content is appended in force.declared_kindis the declaration kind AEAT states; importing after a confirmed declaration requires it.- Return type:
- Returns:
The in-force
ModeloRecordand the reconciliation result.- Raises:
ExternalModeloImportError – The evidence cannot be bound to the work unit, or the import cannot be reconciled with the chain.
- Parameters:
work_unit_id (str)
source_lexical_values_by_casilla_id (Mapping[CasillaKey, str] | None)
evidence_kind (ExternalEvidenceKind)
evidence_reference_id (str)
filing_instance_evidence (FilingInstanceEvidence | None)
declared_kind (FilingDeclarationKind | None)
actor (str)
work_unit_repository (WorkUnitCatalogueRepositoryProtocol | None)
calculation_repository (CalculationRevisionCatalogueRepositoryProtocol | None)
filing_repository (ModeloRecordCatalogueRepositoryProtocol | None)
bucket_event_repository (BucketEventHistoryRepositoryProtocol | None)
justificante_repository (JustificanteRepositoryProtocol | None)
observation_repository (CalculationObservationRepositoryProtocol)
expected_tax_id (str | None)
clock (datetime | None)
source_headers (tuple[ObservedHeaderFact, ...])
operation (PinnedAuthorityOperation | None)
- prepare_external_filing_revision(*, work_unit_id, casilla_values, source_lexical_values_by_casilla_id, evidence_kind, evidence_reference_id, filing_instance_evidence, expected_tax_id, actor, now, work_unit_repository, calculation_repository, justificante_repository)[source]¶
Validate external filing content and stage its presented revision in memory.
Refuses undeclared casillas, missing filing-instance evidence and unbound receipt evidence, then inserts a
PRESENTADOrevision into a revision-guarded copy of the catalogue. Nothing is written: the caller co-commits the returned catalogues with its own filing transition.- Return type:
- Parameters:
work_unit_id (str)
source_lexical_values_by_casilla_id (Mapping[CasillaKey, str] | None)
evidence_kind (ExternalEvidenceKind)
evidence_reference_id (str)
filing_instance_evidence (FilingInstanceEvidence | None)
expected_tax_id (str | None)
actor (str)
now (datetime)
work_unit_repository (WorkUnitCatalogueRepositoryProtocol)
calculation_repository (CalculationRevisionCatalogueRepositoryProtocol)
justificante_repository (JustificanteRepositoryProtocol | None)
- build_external_filing_record(*, filing_record_id, work_unit, calculation_revision_id, filed_at, filed_by, evidence_kind, evidence_reference_id, declaration_kind, member_nif=None, amends_filing_record_id=None, aeat_register=None)[source]¶
Build the in-force, AEAT-origin chain entry for externally presented content.
- Return type:
- Parameters:
filing_record_id (str)
work_unit (WorkUnit)
calculation_revision_id (CalculationRevisionId)
filed_at (datetime)
filed_by (str)
evidence_kind (ExternalEvidenceKind)
evidence_reference_id (str)
declaration_kind (FilingDeclarationKind)
member_nif (str | None)
amends_filing_record_id (str | None)
aeat_register (AeatRegisterRef | None)
- require_bound_justificante_artifact(*, evidence_kind, evidence_reference_id, modelo, filing_year, period, expected_tax_id, justificante_repository)[source]¶
Require matching stored
Justificantemetadata.Justificante-PDF and live-capture imports are treated as receipt-bound baselines: the evidence reference must resolve to stored justificante metadata for the same taxpayer, modelo, filing year, and period. The taxpayer comparison is case-insensitive after stripping.
- Return type:
- Parameters:
evidence_kind (ExternalEvidenceKind)
evidence_reference_id (str)
modelo (str)
filing_year (int)
period (Period)
expected_tax_id (str | None)
justificante_repository (JustificanteRepositoryProtocol)