123 lines
3.9 KiB
Python
123 lines
3.9 KiB
Python
from orc_renaming.models import DocumentScope, DocumentType
|
|
from orc_renaming.normalize import result_is_complete
|
|
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)
|
|
|
|
|
|
def test_correspondence_with_subject_can_skip_llm(config) -> None:
|
|
text = """
|
|
Stadtwerke Musterstadt GmbH
|
|
Datum: 18.07.2026
|
|
Betreff: Änderung Ihres Vertrags
|
|
Sehr geehrte Damen und Herren,
|
|
hiermit informieren wir Sie über eine Änderung.
|
|
"""
|
|
result = extract_with_rules(text, config)
|
|
assert result.document_type == DocumentType.CORRESPONDENCE
|
|
assert result.topic == "Änderung Ihres Vertrags"
|
|
assert result.confidence >= 0.85
|
|
assert result_is_complete(result)
|
|
|
|
|
|
def test_betrag_and_betreuung_are_not_subject_lines(config) -> None:
|
|
text = """
|
|
Betreuung Aufzug 17.249,41 EUR
|
|
Betrag sofort zahlbar ohne Abzug
|
|
"""
|
|
result = extract_with_rules(text, config)
|
|
assert result.topic is None
|
|
|
|
|
|
def test_property_company_blocks_private_fallback(config) -> None:
|
|
config.processing.assume_unmatched_invoices_private = True
|
|
config.companies[0].default_scope = "property"
|
|
config.companies[0].require_property_match = True
|
|
text = """
|
|
Stadtwerke Musterstadt GmbH
|
|
Rechnung
|
|
Rechnungsnummer 123
|
|
Rechnungsdatum: 18.07.2026
|
|
"""
|
|
result = extract_with_rules(text, config)
|
|
assert result.scope == DocumentScope.UNKNOWN
|
|
assert any("benötigt einen Immobilienmarker" in item for item in result.warnings)
|
|
|
|
|
|
def test_unmatched_invoice_private_fallback(config) -> None:
|
|
config.processing.assume_unmatched_invoices_private = True
|
|
text = """
|
|
Stadtwerke Musterstadt GmbH
|
|
Rechnung
|
|
Rechnungsnummer 123
|
|
Rechnungsdatum: 18.07.2026
|
|
"""
|
|
result = extract_with_rules(text, config)
|
|
assert result.scope == DocumentScope.PRIVATE
|
|
assert result.confidence == config.processing.unmatched_private_confidence
|
|
assert any("Privat-Fallback" in item for item in result.evidence)
|