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:
@@ -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."""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user