Source code for cadrumo.application.ledger.structured_invoice_ports
"""Application-owned contract for deterministic structured-invoice reads.The inbound e-invoice parser owns syntax, XML handling, and format-specificvocabularies. The ledger use case needs only the values a structured recordstates, so an outer binding translates the parser's result into thesesyntax-neutral in-memory records before it crosses into the application."""from__future__importannotationsfromdataclassesimportdataclassfromdecimalimportDecimalfromenumimportStrEnumfromtypingimportProtocolfrom...core.document_shapeimportDocumentShape
[docs]classStructuredInvoiceClassificationKind(StrEnum):"""Application-relevant class of a structured invoice document."""ORDINARY="ordinary"CORRECTIVE="corrective"SUMMARY="summary"
[docs]@dataclass(frozen=True,slots=True)classStructuredInvoiceClassification:"""A document class translated from a syntax-specific source code."""source_code:strkind:StructuredInvoiceClassificationKind
[docs]@dataclass(frozen=True,slots=True)classStructuredInvoiceLine:"""One syntax-neutral line read from a structured invoice."""description:str|Nonequantity:Decimal|Noneunit_price:Decimal|Nonetaxable_base:Decimal|Noneiva_rate:Decimal|Noneiva_amount:Decimal|None
[docs]@dataclass(frozen=True,slots=True)classStructuredInvoiceRecord:"""The structured-record facts consumed by ledger extraction."""shape:DocumentShapesupplier_tax_id:str|Nonecustomer_tax_id:str|Nonesupplier_name:str|Nonecustomer_name:str|Nonesupplier_postal_code:str|Nonecustomer_postal_code:str|Nonesupplier_country_code:str|Nonecustomer_country_code:str|Noneinvoice_number:str|Noneinvoice_series:str|Noneinvoice_classification:StructuredInvoiceClassification|Nonerectifies_invoice_number:str|Noneinvoice_date:str|Nonecurrency:str|Nonetaxable_base:Decimal|Noneiva_amount:Decimal|Nonegrand_total:Decimal|Nonerecargo_amount:Decimal|Noneretencion_amount:Decimal|Nonesuplidos_amount:Decimal|Noneiva_category:str|Noneregime_legend:str|Nonerecord_text:strlines:tuple[StructuredInvoiceLine,...]iva_breakdown:tuple[tuple[Decimal|None,Decimal|None,Decimal|None],...]
[docs]classStructuredInvoiceReader(Protocol):"""Required capability for reading one structured invoice from bytes."""def__call__(self,data:bytes)->StructuredInvoiceRecord:"""Return application-owned facts or raise the application read error."""...