fix(validator): accept genuine zero totals in the required-field check
pflichtfelder rejected every invoice whose net, VAT or gross total was 0. The extractor reads an absent total as 0, so this could not tell a missing value from a real zero and rejected tax-exempt / reverse-charge invoices (VAT 0, e.g. customs agent invoices) and zero-sum invoices. A zero total now counts as missing only when the rest of the invoice implies another value: net vs. the line items, VAT total vs. the VAT breakdown, gross vs. net plus VAT. Closes zugferd-esf. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+58
-1
@@ -288,12 +288,69 @@ class TestValidatePflichtfelder:
|
||||
line_total=10.0,
|
||||
)
|
||||
],
|
||||
totals=Totals(line_total_sum=10.0, net=10.0, vat_total=0.0, gross=10.0),
|
||||
totals=Totals(
|
||||
line_total_sum=10.0,
|
||||
net=10.0,
|
||||
vat_total=0.0,
|
||||
gross=11.9,
|
||||
vat_breakdown=[VatBreakdown(rate=19.0, base=10.0, amount=1.9)],
|
||||
),
|
||||
)
|
||||
errors = validate_pflichtfelder(xml_data)
|
||||
assert any(e.field == "totals.vat_total" for e in errors)
|
||||
assert any(e.severity == "critical" for e in errors)
|
||||
|
||||
@staticmethod
|
||||
def _zero_amount_invoice(totals: Totals, line_total: float = 10.0) -> XmlData:
|
||||
return XmlData(
|
||||
invoice_number="INV001",
|
||||
invoice_date="2024-01-15",
|
||||
supplier=Supplier(name="Test Supplier GmbH", vat_id="DE123456789"),
|
||||
buyer=Buyer(name="Test Buyer AG"),
|
||||
line_items=[
|
||||
LineItem(
|
||||
position=1,
|
||||
description="Test Product",
|
||||
quantity=1.0,
|
||||
unit="Stück",
|
||||
unit_price=line_total,
|
||||
line_total=line_total,
|
||||
)
|
||||
],
|
||||
totals=totals,
|
||||
)
|
||||
|
||||
def test_zero_vat_total_on_tax_exempt_invoice_is_valid(self):
|
||||
"""0 EUR VAT is a real value on exempt / reverse-charge invoices."""
|
||||
xml_data = self._zero_amount_invoice(
|
||||
Totals(
|
||||
line_total_sum=10.0,
|
||||
net=10.0,
|
||||
vat_total=0.0,
|
||||
gross=10.0,
|
||||
vat_breakdown=[VatBreakdown(rate=0.0, base=10.0, amount=0.0)],
|
||||
)
|
||||
)
|
||||
errors = validate_pflichtfelder(xml_data)
|
||||
assert not any(e.field and e.field.startswith("totals") for e in errors)
|
||||
|
||||
def test_zero_vat_total_without_breakdown_is_valid(self):
|
||||
"""A missing BT-110 is read as 0 and accepted when nothing contradicts it."""
|
||||
xml_data = self._zero_amount_invoice(
|
||||
Totals(line_total_sum=10.0, net=10.0, vat_total=0.0, gross=10.0)
|
||||
)
|
||||
errors = validate_pflichtfelder(xml_data)
|
||||
assert not any(e.field == "totals.vat_total" for e in errors)
|
||||
|
||||
def test_zero_net_and_gross_on_zero_invoice_are_valid(self):
|
||||
"""A zero-sum invoice legitimately carries net = gross = 0."""
|
||||
xml_data = self._zero_amount_invoice(
|
||||
Totals(line_total_sum=0.0, net=0.0, vat_total=0.0, gross=0.0),
|
||||
line_total=0.0,
|
||||
)
|
||||
errors = validate_pflichtfelder(xml_data)
|
||||
assert not any(e.field and e.field.startswith("totals") for e in errors)
|
||||
|
||||
def test_missing_due_date_warning(self):
|
||||
"""Missing due_date should produce warning, not critical error."""
|
||||
xml_data = XmlData(
|
||||
|
||||
Reference in New Issue
Block a user