Station name as "brand, street, city", grey box on all editable fields

The "grey box around the icons" report turned out not to be a defect: the box
on "10.000 km"/"1 Jahr"/"15" is the wanted pattern, and every value the user
can change should carry it. All .feld inputs and selects now get the grey iOS
fill; inputs with their own visual language (checkbox/radio/range/file) keep
the transparent base rule, so the switches are unaffected.

Fuel stations are now displayed as "Shell, Pascalstr. 8, Ingolstadt" instead of
the bare operator name. New _marke()/_ist_strasse()/_tankstelle() helpers are
shared by both parser paths so Shell and non-Shell receipts format the same.
The brand is only matched against the receipt header - searching the whole text
would let "Total" hit a totals line. Missing parts are dropped instead of
leaving empty comma slots, and without a known brand the operator name takes
its place. station_address still carries the full street and postcode.
test_bekannte_stationen updated to the new format; suite stays green.

installationspaket/ is versioned from now on (user request). It contains no
real vehicle data - only the example profile with empty FIN/plate placeholders.
Keep it in sync whenever pyscript/ or www/ changes.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
2026-08-16 12:52:31 +02:00
parent 39da68cd87
commit fb38c297bd
49 changed files with 11131 additions and 27 deletions
+76 -10
View File
@@ -99,6 +99,46 @@ _GESAMT_WOERTER = ("GESAMT", "ABSOLUT", "ENDBETRAG", "ZUZAHLEN", "TOTAL", "SUMME
# nennen aber nie den bezahlten Rechnungsbetrag.
_STEUER_WOERTER = ("MWST", "UST", "VAT", "STEUER", "NETTO")
# Kraftstoffmarken, wie sie im Belegkopf stehen. Bewusst nur dort gesucht (die
# ersten Zeilen), nicht im ganzen Text: "Total" wäre sonst z. B. auch als
# Summenzeile ein Treffer. Längere Namen zuerst, damit "TotalEnergies" nicht
# als "Total" endet. Die Schreibweise hier ist die, die angezeigt wird - auf
# Bons steht die Marke meist in Großbuchstaben ("SHELL STATION").
_MARKEN = (
"TotalEnergies", "Total", "Aral", "Shell", "Eni", "Agip", "Esso", "OMV",
"Avia", "Turmöl", "Turmoel", "Orlen", "Tamoil", "Westfalen", "Allguth",
"Classic", "Sprint", "Raiffeisen", "BayWa", "Elan", "HEM", "Star", "JET",
"bft", "BP", "Q1",
)
_STRASSE_WOERTER = r"(?:stra(?:ss|ß)e|str\.|gasse|weg|platz|allee|ring|damm|chaussee)"
def _marke(zeilen):
"""Markenname aus dem Belegkopf ("SHELL STATION" -> "Shell"). None, wenn
keine bekannte Marke draufsteht - dann bleibt es beim Betreibernamen."""
kopf = "\n".join(zeilen[:8])
for marke in _MARKEN:
if re.search(r"\b" + re.escape(marke) + r"\b", kopf, re.IGNORECASE):
return marke
return None
def _ist_strasse(zeile):
"""Straßenzeilen tragen eine Hausnummer oder ein Straßenwort - der
Betreibername ("AUTO B. FRISCHMANN GMBH") tut beides nicht."""
if not zeile:
return False
return bool(re.search(r"\d", zeile) or re.search(_STRASSE_WOERTER, zeile, re.IGNORECASE))
def _tankstelle(marke, strasse, ort, ersatzname=None):
"""Anzeigename der Tankstelle im Format "Marke, Straße, Ort" (§ Anzeige im
Frontend, Feld station_name). Fehlende Teile fallen weg statt als leere
Kommastelle stehen zu bleiben - nicht jeder Beleg nennt eine Straße. Ohne
erkennbare Marke tritt der Betreibername an ihre Stelle."""
teile = [t for t in (marke or ersatzname, strasse, ort) if t]
return ", ".join(teile) if teile else None
def _parsen(text):
def suchen(muster, *, pflicht=True, flags=re.MULTILINE):
@@ -191,7 +231,15 @@ def _parsen(text):
"ts_payment": ts_payment,
"ts_tse": ts_tse,
"station_id": station_id,
"station_name": station.group("name").strip(),
# Anzeigename "Marke, Straße, Ort" (siehe _tankstelle). Der Ort steht
# auf dem Bon als "85057 Ingolstadt" - die PLZ gehört nur in die
# ausführliche station_address darunter, nicht in den Anzeigenamen.
"station_name": _tankstelle(
_marke(text.splitlines()),
station.group("strasse").strip(),
re.sub(r"^\d{4,5}\s+", "", station.group("ort").strip()),
ersatzname=station.group("name").strip(),
),
"station_address": f"{station.group('strasse').strip()}, {station.group('ort').strip()}",
"article_no": article_no,
"product_name": product_name,
@@ -242,24 +290,42 @@ def _parsen_generisch(text):
# fünfstellig (AT/DE). Deshalb nicht mehr drei feste Zeilen hintereinander
# verlangen, sondern im Belegkopf die erste Zeile mit PLZ+Ort suchen; der
# Name ist die erste Textzeile darüber.
plz_treffer = None
plz_zeile = None
for i, zeile in enumerate(zeilen[:12]):
if re.search(r"\b\d{4,5}\s+[A-Za-zÄÖÜäöüß]", zeile):
plz_zeile = i
treffer = re.search(r"\b\d{4,5}\s+([A-Za-zÄÖÜäöüß][^\n]*)$", zeile)
if treffer:
plz_treffer, plz_zeile = treffer, i
break
station_name = None
ort = None
strasse = None
betreiber = None
station_address = None
if plz_zeile is not None:
if plz_treffer is not None:
ort = plz_treffer.group(1).strip(" ,.-")
station_address = zeilen[plz_zeile].strip()
# Die Straße steht entweder vor der PLZ auf derselben Zeile
# ("Musterstr. 5, 80331 München") oder auf der Zeile darüber.
vor_plz = zeilen[plz_zeile][: plz_treffer.start()].strip(" ,.-")
if _ist_strasse(vor_plz):
strasse = vor_plz
for zeile in reversed(zeilen[:plz_zeile]):
if zeile.strip():
station_name = zeile.strip()
break
if station_name is None:
if not zeile.strip():
continue
if strasse is None and _ist_strasse(zeile.strip()):
strasse = zeile.strip()
continue
betreiber = zeile.strip()
break
if betreiber is None:
for zeile in zeilen[:5]:
if zeile.strip():
station_name = zeile.strip()
betreiber = zeile.strip()
break
if station_address and strasse and strasse not in station_address:
station_address = f"{strasse}, {station_address}"
station_name = _tankstelle(_marke(zeilen), strasse, ort, ersatzname=betreiber)
# ---- Gesamtbetrag ------------------------------------------------------
# Zeilenweise statt über den ganzen Text, aus zwei Gründen, die beide an