Backend: Kaufpreis aus Beleg-PDF schätzen

guess_price_cents zieht den Kaufpreis aus dem Belegtext: bevorzugt den Betrag
nach einem Summen-Stichwort (Gesamtbetrag/Total/…), sonst den groessten Betrag.
Versteht Tausendertrenner (1'299.00) und deutsches Format (1.299,00). Der
Upload liefert den Vorschlag als suggested_price_cents mit. 5 neue Tests.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Scarriffle
2026-07-26 20:57:30 +02:00
parent 61270e6d00
commit ba65e48d47
4 changed files with 95 additions and 9 deletions

View File

@@ -2,7 +2,7 @@
from datetime import date
from app.services.warranty import guess_warranty_until
from app.services.warranty import guess_price_cents, guess_warranty_until
def test_zeitraum_plus_kaufdatum_vom_stueck():
@@ -37,3 +37,30 @@ def test_ohne_hinweise_kein_vorschlag():
def test_leerer_text_ist_none():
assert guess_warranty_until("", acquired_on=date(2024, 1, 1)) is None
# ---- Preis ----
def test_preis_nahe_total_stichwort():
text = "Artikel 49.00\nVersand 5.90\nGesamtbetrag: 54.90 CHF"
assert guess_price_cents(text) == 5490
def test_preis_mit_tausendertrenner_apostroph():
text = "Total CHF 1'299.00"
assert guess_price_cents(text) == 129900
def test_preis_deutsches_format():
text = "Rechnungsbetrag 1.299,00 EUR"
assert guess_price_cents(text) == 129900
def test_preis_ohne_stichwort_nimmt_groessten_betrag():
text = "Position A 12,90\nPosition B 199,00\nDanke."
assert guess_price_cents(text) == 19900
def test_preis_ohne_betrag_ist_none():
assert guess_price_cents("Kein Preis hier.") is None
assert guess_price_cents("") is None