69 lines
2.1 KiB
Python
69 lines
2.1 KiB
Python
from orc_renaming.models import DocumentScope, DocumentType
|
|
from orc_renaming.rules import extract_with_rules
|
|
|
|
|
|
def test_property_invoice_is_recognized(config) -> None:
|
|
text = """
|
|
Stadtwerke Musterstadt GmbH
|
|
Rechnung
|
|
Rechnungsnummer 2026-123
|
|
Rechnungsdatum: 18.07.2026
|
|
Lieferstelle Musterstraße 12
|
|
Vertragskonto 47110815
|
|
Rechnungsbetrag 123,45 EUR
|
|
"""
|
|
result = extract_with_rules(text, config)
|
|
|
|
assert result.document_type == DocumentType.INVOICE
|
|
assert result.scope == DocumentScope.PROPERTY
|
|
assert result.property_id == "WH1"
|
|
assert result.company == "Stadtwerke-Musterstadt"
|
|
assert result.document_date.isoformat() == "2026-07-18"
|
|
assert result.confidence >= 0.9
|
|
|
|
|
|
def test_private_invoice_needs_explicit_marker(config) -> None:
|
|
text = """
|
|
Beliebige Firma GmbH
|
|
Rechnung
|
|
Rechnungsnummer 99
|
|
Rechnungsdatum: 18.07.2026
|
|
Empfänger: Max Beispiel, Privatweg 8
|
|
"""
|
|
result = extract_with_rules(text, config)
|
|
assert result.document_type == DocumentType.INVOICE
|
|
assert result.scope == DocumentScope.PRIVATE
|
|
|
|
|
|
def test_unmatched_invoice_is_not_assumed_private(config) -> None:
|
|
text = """
|
|
Unbekannte Firma
|
|
Rechnung
|
|
Rechnungsnummer 99
|
|
Rechnungsdatum: 18.07.2026
|
|
"""
|
|
result = extract_with_rules(text, config)
|
|
assert result.scope == DocumentScope.UNKNOWN
|
|
|
|
|
|
def test_invalid_date_is_ignored(config) -> None:
|
|
result = extract_with_rules(
|
|
"Rechnung Rechnungsnummer 1 Rechnungsdatum: 35.17.2026",
|
|
config,
|
|
)
|
|
assert result.document_date is None
|
|
|
|
|
|
def test_multiple_property_matches_are_not_guessed(config) -> None:
|
|
second = config.properties[0].model_copy(
|
|
update={"id": "WH2", "name": "Zweites Haus", "markers": ["Objektcode B-2"]}
|
|
)
|
|
config.properties.append(second)
|
|
result = extract_with_rules(
|
|
"Rechnung Rechnungsnummer 1 Musterstraße 12 Objektcode B-2",
|
|
config,
|
|
)
|
|
assert result.scope == DocumentScope.UNKNOWN
|
|
assert result.property_id is None
|
|
assert any("Mehrere Immobilien" in item for item in result.warnings)
|