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
+12 -3
View File
@@ -435,9 +435,15 @@ def parse_zugferd_xml(xml_bytes: bytes) -> XmlData:
"//rsm:ExchangedDocument/ram:IssueDateTime/udt:DateTimeString[@format='102']/text()",
namespaces=NAMESPACES,
)
# BT-9 payment due date
due_date = xml_root.xpath(
"//ram:ApplicableHeaderTradeAgreement/ram:ApplicableTradeDeliveryTerms/"
"ram:Description/text()",
"//ram:ApplicableHeaderTradeSettlement/ram:SpecifiedTradePaymentTerms/"
"ram:DueDateDateTime/udt:DateTimeString/text()",
namespaces=NAMESPACES,
)
# BT-10 buyer reference (Leitweg-ID on XRechnung invoices)
buyer_reference = xml_root.xpath(
"//ram:ApplicableHeaderTradeAgreement/ram:BuyerReference/text()",
namespaces=NAMESPACES,
)
notes = xml_root.xpath(
@@ -453,7 +459,10 @@ def parse_zugferd_xml(xml_bytes: bytes) -> XmlData:
return XmlData(
invoice_number=invoice_number[0] if invoice_number else "",
invoice_date=_normalize_cii_date(invoice_date[0]) if invoice_date else "",
due_date=due_date[0] if due_date else None,
due_date=_normalize_cii_date(due_date[0]) if due_date else None,
buyer_reference=(buyer_reference[0].strip() or None)
if buyer_reference
else None,
supplier=parse_supplier(xml_root),
buyer=parse_buyer(xml_root),
line_items=parse_line_items(xml_root),