Initial version of the E-Invoice solution of JR IT Services

This commit is contained in:
2026-02-16 17:02:03 +01:00
commit e0c15fc7f2
36 changed files with 1407 additions and 0 deletions

22
jr_einvoice/facturx.py Normal file
View File

@@ -0,0 +1,22 @@
from __future__ import annotations
from pathlib import Path
from decimal import Decimal
from pycheval import EN16931Invoice, Money, generate_xml
from .models import Invoice
from .calc import compute_totals
def generate_facturx_xml(inv: Invoice, out_xml: Path, logger) -> Path:
out_xml.parent.mkdir(parents=True, exist_ok=True)
totals = compute_totals(inv)
invoice = EN16931Invoice(
invoice_number=inv.meta.invoice_number,
invoice_date=inv.meta.invoice_date,
currency=inv.meta.currency,
grand_total=Money(str(Decimal(str(totals.gross_total)).quantize(Decimal("0.01"))), inv.meta.currency),
)
xml_string = generate_xml(invoice)
out_xml.write_text(xml_string, encoding="utf-8")
logger.info("Wrote Factur-X XML: %s", out_xml)
return out_xml