Allow zero-euro line item amounts
This commit is contained in:
+32
-9
@@ -1,6 +1,5 @@
|
||||
"""Tests for ZUGFeRD validator using TDD approach."""
|
||||
|
||||
import pytest
|
||||
from src.models import (
|
||||
XmlData,
|
||||
Supplier,
|
||||
@@ -9,8 +8,6 @@ from src.models import (
|
||||
Totals,
|
||||
VatBreakdown,
|
||||
PaymentTerms,
|
||||
ErrorDetail,
|
||||
ValidationResult,
|
||||
ValidateRequest,
|
||||
)
|
||||
from src.validator import (
|
||||
@@ -352,8 +349,8 @@ class TestValidatePflichtfelder:
|
||||
assert any(e.field == "line_items[0].quantity" for e in errors)
|
||||
assert any(e.severity == "critical" for e in errors)
|
||||
|
||||
def test_missing_line_item_unit_price_critical(self):
|
||||
"""Missing line_item.unit_price (zero) should produce critical error."""
|
||||
def test_zero_euro_line_item_amounts_allowed(self):
|
||||
"""Zero-valued line item prices should count as present."""
|
||||
xml_data = XmlData(
|
||||
invoice_number="INV001",
|
||||
invoice_date="2024-01-15",
|
||||
@@ -366,6 +363,29 @@ class TestValidatePflichtfelder:
|
||||
quantity=1.0,
|
||||
unit="Stück",
|
||||
unit_price=0.0,
|
||||
line_total=0.0,
|
||||
)
|
||||
],
|
||||
totals=Totals(line_total_sum=10.0, net=10.0, vat_total=19.0, gross=29.0),
|
||||
)
|
||||
errors = validate_pflichtfelder(xml_data)
|
||||
assert not any(e.field == "line_items[0].unit_price" for e in errors)
|
||||
assert not any(e.field == "line_items[0].line_total" for e in errors)
|
||||
|
||||
def test_missing_line_item_unit_price_critical(self):
|
||||
"""Missing line_item.unit_price should produce critical error."""
|
||||
xml_data = 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=None,
|
||||
line_total=10.0,
|
||||
)
|
||||
],
|
||||
@@ -376,7 +396,7 @@ class TestValidatePflichtfelder:
|
||||
assert any(e.severity == "critical" for e in errors)
|
||||
|
||||
def test_missing_line_item_line_total_critical(self):
|
||||
"""Missing line_item.line_total (zero) should produce critical error."""
|
||||
"""Missing line_item.line_total should produce critical error."""
|
||||
xml_data = XmlData(
|
||||
invoice_number="INV001",
|
||||
invoice_date="2024-01-15",
|
||||
@@ -389,7 +409,7 @@ class TestValidatePflichtfelder:
|
||||
quantity=1.0,
|
||||
unit="Stück",
|
||||
unit_price=10.0,
|
||||
line_total=0.0,
|
||||
line_total=None,
|
||||
)
|
||||
],
|
||||
totals=Totals(line_total_sum=10.0, net=10.0, vat_total=0.0, gross=10.0),
|
||||
@@ -499,7 +519,7 @@ class TestValidateBetraege:
|
||||
errors = validate_betraege(xml_data)
|
||||
assert any(e.error_code == "calculation_mismatch" for e in errors)
|
||||
assert any(
|
||||
"line_total" in e.field
|
||||
e.field is not None and "line_total" in e.field
|
||||
for e in errors
|
||||
if e.error_code == "calculation_mismatch"
|
||||
)
|
||||
@@ -597,7 +617,7 @@ class TestValidateBetraege:
|
||||
),
|
||||
)
|
||||
errors = validate_betraege(xml_data)
|
||||
assert any("vat_breakdown" in e.field for e in errors)
|
||||
assert any(e.field is not None and "vat_breakdown" in e.field for e in errors)
|
||||
assert any(e.error_code == "calculation_mismatch" for e in errors)
|
||||
|
||||
def test_totals_vat_total_mismatch(self):
|
||||
@@ -1040,6 +1060,7 @@ class TestValidateInvoice:
|
||||
result = validate_invoice(request)
|
||||
assert result.is_valid is True
|
||||
assert len(result.errors) == 0
|
||||
assert result.summary is not None
|
||||
assert result.summary["checks_passed"] == 2
|
||||
|
||||
def test_warnings_not_critical(self):
|
||||
@@ -1134,6 +1155,7 @@ class TestValidateInvoice:
|
||||
)
|
||||
result = validate_invoice(request)
|
||||
# Should have errors from PDF comparison
|
||||
assert result.summary is not None
|
||||
assert result.summary["total_checks"] == 1
|
||||
|
||||
def test_validation_time_populated(self):
|
||||
@@ -1187,5 +1209,6 @@ class TestValidateInvoice:
|
||||
)
|
||||
result = validate_invoice(request)
|
||||
# Should handle gracefully - no errors from invalid check
|
||||
assert result.summary is not None
|
||||
assert result.summary["total_checks"] == 0
|
||||
assert result.is_valid is True # No critical errors
|
||||
|
||||
Reference in New Issue
Block a user