feat: extract due date and buyer reference, require it on XRechnung

- CII: due_date is read from the payment due date (BT-9) instead of the
  delivery terms description, normalized to YYYY-MM-DD
- new field buyer_reference (BT-10, the Leitweg-ID) for CII and UBL
- /validate accepts an optional profile; on XRECHNUNG_* profiles a
  missing buyer reference is a critical error (BR-DE-15)

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
2026-11-11 18:33:08 +01:00
co-authored by Claude Fable 5.2
parent 4ff994a299
commit fa9eaa4f82
8 changed files with 117 additions and 6 deletions
+1
View File
@@ -77,6 +77,7 @@ def test_fixture_sweep(filename: str) -> None:
xml_data=result.xml_data.model_dump(),
pdf_text=result.pdf_text,
checks=ALL_CHECKS,
profile=result.zugferd_profil,
)
validation = validate_invoice(request)
critical_fields = {error.field for error in validation.errors}
+2
View File
@@ -6,6 +6,7 @@ tests/fixtures/real/, verify it contains no real-world data, and add a test
here that locks in the correct behavior.
"""
import re
from io import BytesIO
from pathlib import Path
@@ -51,6 +52,7 @@ class TestFcTaxNumberBasisQuantityInvoice:
data = result.xml_data
assert data.invoice_number == "4711"
assert re.fullmatch(r"\d{4}-\d{2}-\d{2}", data.due_date)
assert data.supplier.tax_number == "1112223334444"
assert data.supplier.vat_id is None
assert data.supplier.email == "rechnung@beispielwerkstatt.example"
+42
View File
@@ -111,6 +111,7 @@ class TestPlainXml:
assert result.extraction_meta.xml_attachment_name is None
assert result.xml_data.invoice_number == "123456XX"
assert result.xml_data.invoice_date == "2016-04-04"
assert result.xml_data.buyer_reference == "04011000-12345-03"
assert result.xml_data.totals.gross == pytest.approx(336.9)
def test_ubl_xml(self):
@@ -124,6 +125,7 @@ class TestPlainXml:
data = result.xml_data
assert data.invoice_number == "123456XX"
assert data.invoice_date == "2016-04-04"
assert data.buyer_reference == "04011000-12345-03"
assert data.currency == "EUR"
assert data.supplier.name == "[Seller name]"
assert data.supplier.vat_id == "DE 123456789"
@@ -173,6 +175,46 @@ class TestPlainXml:
assert not result.xml_raw.startswith("")
class TestBuyerReference:
"""BT-10 (Leitweg-ID) is mandatory on XRechnung invoices only."""
def _data_without_reference(self):
xml_data = extract_invoice(UBL_XML.read_bytes()).xml_data
xml_data.buyer_reference = None
return xml_data.model_dump()
def test_missing_on_xrechnung_is_critical(self):
request = ValidateRequest(
xml_data=self._data_without_reference(),
checks=["pflichtfelder"],
profile="XRECHNUNG_3.0",
)
validation = validate_invoice(request)
assert validation.is_valid is False
assert [e.field for e in validation.errors] == ["buyer_reference"]
@pytest.mark.parametrize("profile", [None, "EN16931", "PEPPOL_BIS_BILLING_3.0"])
def test_missing_on_other_profiles_is_fine(self, profile):
request = ValidateRequest(
xml_data=self._data_without_reference(),
checks=["pflichtfelder"],
profile=profile,
)
assert validate_invoice(request).errors == []
def test_present_on_xrechnung_passes(self):
result = extract_invoice(CII_XML.read_bytes())
request = ValidateRequest(
xml_data=result.xml_data.model_dump(),
checks=ALL_CHECKS,
profile=result.zugferd_profil,
)
assert validate_invoice(request).errors == []
class TestUblCreditNote:
"""UBL CreditNote uses its own line and quantity element names."""