Source code for aeat.application.storage.calc_sheets._evidence
"""Evidence adapters for calc-sheets workbook export plans.:func:`sheet_evidence_from_ledger_filing` projects:class:`LedgerFilingEvidence` into a :class:`SheetEvidenceFacet` made of:class:`SheetEvidenceContributorRow` and :class:`SheetEvidenceManualEntry`records for the workbook evidence surface.The adapter is deliberately attribution-driven. Ledger evidence names thecontributing transactions and manual facts; the caller supplies the mapping fromeach contributor to the canonical :class:`CasillaId` values it supports so thismodule never guesses modelo-specific tax meaning from row contents.See Also: :class:`aeat.domain.modelos._ledger_filing_snapshot.LedgerFilingEvidence` Bundled fact basis attached to a ledger-derived calculation revision. :class:`SheetEvidenceFacet` Workbook-plan evidence facet rendered into the Evidencia tab and JSON sidecar."""from__future__importannotationsfromcollections.abcimportIterable,Mappingfrom....domain.calculations.registryimportCasillaIdfrom....domain.modelosimportLedgerFilingEvidencefrom._errorsimportCalcSheetsEngineErrorfrom._recordsimportSheetEvidenceContributorRow,SheetEvidenceFacet,SheetEvidenceManualEntry
[docs]defsheet_evidence_from_ledger_filing(evidence:LedgerFilingEvidence,*,casilla_ids_by_contributor_id:Mapping[str,Iterable[CasillaId]],)->SheetEvidenceFacet:"""Project bundled filing evidence into the per-casilla workbook facet. :class:`LedgerFilingEvidence` is contributor-oriented; the workbook evidence surface is casilla-oriented. The caller must therefore provide the generic attribution map from each contributor transaction id to the canonical :class:`CasillaId` values it supports. Missing attribution raises :class:`CalcSheetsEngineError` instead of being guessed from modelo-specific tax facts. Returns: :class:`SheetEvidenceFacet`: The projected evidence facet. """contributor_rows:list[SheetEvidenceContributorRow]=[]forrowinevidence.rows:contributor_casilla_ids=tuple(casilla_ids_by_contributor_id.get(row.transaction_id,()))ifnotcontributor_casilla_ids:raiseCalcSheetsEngineError(f"ledger filing evidence contributor {row.transaction_id!r} has no workbook casilla attribution",)forcasilla_idincontributor_casilla_ids:contributor_rows.append(SheetEvidenceContributorRow(casilla_id=casilla_id,transaction_id=row.transaction_id,amount=row.amount,currency=row.currency,taxable_base=row.taxable_base,iva_rate=row.iva_rate,iva_amount=row.iva_amount,counterparty=row.counterparty,attachment_ids=row.attachment_ids,document_link_ids=row.document_link_ids,legal_refs=row.legal_refs,source_refs=row.source_refs,),)manual_entries=tuple(SheetEvidenceManualEntry(casilla_id=entry.casilla_id,value=entry.value,kind=entry.kind,note=entry.note,legal_refs=entry.legal_refs,source_refs=entry.source_refs,)forentryinevidence.manual_entries)returnSheetEvidenceFacet(snapshot_fingerprint=evidence.snapshot_fingerprint,contributor_rows=tuple(contributor_rows),manual_entries=manual_entries,)