feat: Zeilenfilter sichtbar, mit auswaehlbaren Werten
Der Filter steckte in einem zugeklappten Bereich und der Wert musste
blind getippt werden – entsprechend importierte man den Revolut-Auszug
mit allen Produkten in ein Konto, was den Saldo-Abgleich unmoeglich
macht.
Die Rohvorschau liefert jetzt je Spalte die wiederkehrenden Werte samt
Zeilenzahl. Hat eine Datei so eine Spalte, steht der Filter offen sichtbar
mit der Ueberschrift "Diese Datei enthaelt mehrere Konten", und der Wert
wird aus einer Liste gewaehlt ("Giro (530 Zeilen)").
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -172,8 +172,21 @@ def read_rows(data: bytes, template: ImportTemplate) -> list[list[str]]:
|
|||||||
return rows
|
return rows
|
||||||
|
|
||||||
|
|
||||||
|
# Eine Spalte taugt als Zeilenfilter, wenn sie die Datei in wenige, klar
|
||||||
|
# benannte Gruppen teilt – etwa „Produkt" bei Revolut (Giro, Erspartes,
|
||||||
|
# Anlagekonto). Mehr als eine Handvoll Werte ist keine Gruppe mehr, sondern
|
||||||
|
# ein Datenfeld wie Empfänger oder Betrag.
|
||||||
|
MAX_FILTERWERTE = 12
|
||||||
|
|
||||||
|
|
||||||
def preview_raw(data: bytes, template: ImportTemplate, limit: int = 8) -> dict:
|
def preview_raw(data: bytes, template: ImportTemplate, limit: int = 8) -> dict:
|
||||||
"""Rohe erste Zeilen (zum Spalten-Zuordnen im Template-Editor)."""
|
"""Rohe erste Zeilen (zum Spalten-Zuordnen im Template-Editor).
|
||||||
|
|
||||||
|
Liefert zusätzlich je Spalte die wählbaren Filterwerte mit Zeilenzahl.
|
||||||
|
Revolut legt alle Produkte in EINE Datei, jedes mit eigener Kontostand-
|
||||||
|
Spalte; ohne Filter zählen die Bewegungen doppelt und der Saldo-Abgleich
|
||||||
|
kann gar nicht aufgehen. Die Werte hier zu kennen erspart das Raten.
|
||||||
|
"""
|
||||||
text = decode_bytes(data, template.encoding)
|
text = decode_bytes(data, template.encoding)
|
||||||
delim = (template.delimiter or ";")[0]
|
delim = (template.delimiter or ";")[0]
|
||||||
reader = csv.reader(io.StringIO(text), delimiter=delim)
|
reader = csv.reader(io.StringIO(text), delimiter=delim)
|
||||||
@@ -183,7 +196,24 @@ def preview_raw(data: bytes, template: ImportTemplate, limit: int = 8) -> dict:
|
|||||||
if template.has_header and len(rows) > body_start:
|
if template.has_header and len(rows) > body_start:
|
||||||
header = rows[body_start]
|
header = rows[body_start]
|
||||||
body_start += 1
|
body_start += 1
|
||||||
return {"header": header, "rows": rows[body_start: body_start + limit]}
|
body = rows[body_start:]
|
||||||
|
|
||||||
|
filterwerte: dict[int, list[dict]] = {}
|
||||||
|
breite = max((len(r) for r in body), default=0)
|
||||||
|
for i in range(breite):
|
||||||
|
zaehler = Counter((r[i] or "").strip() for r in body if i < len(r))
|
||||||
|
zaehler.pop("", None)
|
||||||
|
# Wiederholen sich die Werte nicht, ist es keine Gruppe, sondern ein
|
||||||
|
# Datenfeld wie Empfänger oder Betrag.
|
||||||
|
if 2 <= len(zaehler) <= MAX_FILTERWERTE and len(zaehler) < len(body):
|
||||||
|
filterwerte[i] = [{"value": v, "count": n} for v, n in zaehler.most_common()]
|
||||||
|
|
||||||
|
return {
|
||||||
|
"header": header,
|
||||||
|
"rows": body[:limit],
|
||||||
|
"row_count": len(body),
|
||||||
|
"filter_values": filterwerte,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
def import_hash(account_id: int, d: date | None, amount_cents: int | None, payee: str | None) -> str:
|
def import_hash(account_id: int, d: date | None, amount_cents: int | None, payee: str | None) -> str:
|
||||||
|
|||||||
@@ -576,3 +576,32 @@ def test_kurzer_erkennungstext_trifft_nicht_mitten_im_wort(admin):
|
|||||||
assert typ["TWINT EUROBUS AG"] == "expense"
|
assert typ["TWINT EUROBUS AG"] == "expense"
|
||||||
# Auch als eigenständiges Wort verbindet der Erkennungs-Text keine Konten mehr.
|
# Auch als eigenständiges Wort verbindet der Erkennungs-Text keine Konten mehr.
|
||||||
assert typ["Umbuchung"] == "expense"
|
assert typ["Umbuchung"] == "expense"
|
||||||
|
|
||||||
|
|
||||||
|
MEHRERE_PRODUKTE = (
|
||||||
|
"Produkt;Datum;Betrag;Empfaenger;Zweck\n"
|
||||||
|
"Giro;01.03.2026;-10,00;Coop;\n"
|
||||||
|
"Erspartes;01.03.2026;0,50;Aufrundung;\n"
|
||||||
|
"Giro;02.03.2026;-20,00;Migros;\n"
|
||||||
|
"Anlagekonto;02.03.2026;-100,00;Depot;\n"
|
||||||
|
"Giro;03.03.2026;-5,00;Kiosk;\n"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_rohvorschau_nennt_die_waehlbaren_filterwerte(admin):
|
||||||
|
"""Revolut legt alle Produkte in EINE Datei. Damit man den Zeilenfilter
|
||||||
|
setzen kann, ohne den Wert zu erraten, liefert die Vorschau die Werte je
|
||||||
|
Spalte samt Zeilenzahl mit."""
|
||||||
|
r = admin.post(
|
||||||
|
"/api/imports/raw",
|
||||||
|
files={"file": ("m.csv", io.BytesIO(MEHRERE_PRODUKTE.encode("utf-8")), "text/csv")},
|
||||||
|
data={"delimiter": ";", "encoding": "utf-8", "has_header": "true", "skip_rows": "0"},
|
||||||
|
)
|
||||||
|
assert r.status_code == 200, r.text
|
||||||
|
daten = r.json()
|
||||||
|
assert daten["row_count"] == 5
|
||||||
|
produkte = daten["filter_values"]["0"]
|
||||||
|
assert [p["value"] for p in produkte] == ["Giro", "Erspartes", "Anlagekonto"]
|
||||||
|
assert produkte[0]["count"] == 3
|
||||||
|
# Spalten mit lauter verschiedenen Werten sind keine Gruppen.
|
||||||
|
assert "3" not in daten["filter_values"]
|
||||||
|
|||||||
@@ -355,10 +355,12 @@
|
|||||||
"filterValue": "mit dem Wert",
|
"filterValue": "mit dem Wert",
|
||||||
"filterValuePlaceholder": "z. B. Giro",
|
"filterValuePlaceholder": "z. B. Giro",
|
||||||
"filterNone": "— kein Filter —",
|
"filterNone": "— kein Filter —",
|
||||||
"filterHint": "Revolut legt alle Pockets (Giro, Erspartes, Anlagekonto …) in EINE Datei, jedes mit eigenem Kontostand. Filtere hier auf ein Produkt und lege für die anderen eigene Konten an – sonst zählen die Pocket-Bewegungen doppelt.",
|
"filterHint": "Revolut legt alle Produkte (Giro, Erspartes, Anlagekonto …) in EINE Datei, jedes mit eigenem Kontostand. Wähle hier eines aus und lies die übrigen mit einem eigenen Konto nochmal ein – sonst zählen die Bewegungen doppelt.",
|
||||||
"removeEntry": "Eintrag entfernen",
|
"removeEntry": "Eintrag entfernen",
|
||||||
"removeEntryConfirm": "Den Verlaufs-Eintrag „{{file}}“ entfernen? Die Buchungen sind bereits zurückgenommen.",
|
"removeEntryConfirm": "Den Verlaufs-Eintrag „{{file}}“ entfernen? Die Buchungen sind bereits zurückgenommen.",
|
||||||
"reconMixedHint": "Enthält die Datei mehrere Konten oder Produkte? Revolut legt Giro, Erspartes und Anlagekonto in EINE Datei, jedes mit eigener Kontostand-Spalte. Dann greift der Abgleich erst, wenn du oben den Zeilenfilter setzt (z. B. Produkt = Giro) und die übrigen Produkte einzeln einliest."
|
"reconMixedHint": "Enthält die Datei mehrere Konten oder Produkte? Revolut legt Giro, Erspartes und Anlagekonto in EINE Datei, jedes mit eigener Kontostand-Spalte. Dann greift der Abgleich erst, wenn du oben den Zeilenfilter setzt (z. B. Produkt = Giro) und die übrigen Produkte einzeln einliest.",
|
||||||
|
"filterTitle": "Diese Datei enthält mehrere Konten",
|
||||||
|
"filterValueOption": "{{value}} ({{count}} Zeilen)"
|
||||||
},
|
},
|
||||||
"password": {
|
"password": {
|
||||||
"show": "Passwort anzeigen",
|
"show": "Passwort anzeigen",
|
||||||
|
|||||||
@@ -355,10 +355,12 @@
|
|||||||
"filterValue": "with value",
|
"filterValue": "with value",
|
||||||
"filterValuePlaceholder": "e.g. Current",
|
"filterValuePlaceholder": "e.g. Current",
|
||||||
"filterNone": "— no filter —",
|
"filterNone": "— no filter —",
|
||||||
"filterHint": "Revolut puts every pocket (Current, Savings, Investments …) into ONE file, each with its own balance. Filter to one product here and create separate accounts for the others – otherwise pocket movements are counted twice.",
|
"filterHint": "Revolut puts every product (current, savings, investment …) into ONE file, each with its own balance. Pick one here and import the others separately into their own accounts – otherwise the movements count twice.",
|
||||||
"removeEntry": "Remove entry",
|
"removeEntry": "Remove entry",
|
||||||
"removeEntryConfirm": "Remove the history entry “{{file}}”? Its transactions have already been undone.",
|
"removeEntryConfirm": "Remove the history entry “{{file}}”? Its transactions have already been undone.",
|
||||||
"reconMixedHint": "Does the file hold several accounts or products? Revolut puts current, savings and investment into ONE file, each with its own balance column. The check only works once you set the row filter above (e.g. Product = Current) and import the other products separately."
|
"reconMixedHint": "Does the file hold several accounts or products? Revolut puts current, savings and investment into ONE file, each with its own balance column. The check only works once you set the row filter above (e.g. Product = Current) and import the other products separately.",
|
||||||
|
"filterTitle": "This file holds several accounts",
|
||||||
|
"filterValueOption": "{{value}} ({{count}} rows)"
|
||||||
},
|
},
|
||||||
"password": {
|
"password": {
|
||||||
"show": "Show password",
|
"show": "Show password",
|
||||||
|
|||||||
+42
-17
@@ -218,6 +218,12 @@ export default function Import() {
|
|||||||
}));
|
}));
|
||||||
}, [raw]);
|
}, [raw]);
|
||||||
|
|
||||||
|
// Spalten, die die Datei in wenige Gruppen teilen (Revolut: „Produkt").
|
||||||
|
const filterSpalten = useMemo(
|
||||||
|
() => colOptions.filter((c) => raw?.filter_values?.[String(c.i)]),
|
||||||
|
[colOptions, raw],
|
||||||
|
);
|
||||||
|
|
||||||
const expenseGroups = useMemo(() => gruppenFuer(groups, "expense"), [groups]);
|
const expenseGroups = useMemo(() => gruppenFuer(groups, "expense"), [groups]);
|
||||||
const incomeGroups = useMemo(() => gruppenFuer(groups, "income"), [groups]);
|
const incomeGroups = useMemo(() => gruppenFuer(groups, "income"), [groups]);
|
||||||
|
|
||||||
@@ -521,6 +527,42 @@ export default function Import() {
|
|||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{/* Revolut legt alle Produkte in EINE Datei. Ohne Filter zaehlen die
|
||||||
|
Bewegungen doppelt – deshalb steht der Filter offen, sobald die
|
||||||
|
Datei eine Spalte mit wenigen wiederkehrenden Werten hat. */}
|
||||||
|
{filterSpalten.length > 0 && (
|
||||||
|
<div className="alert" style={{ marginTop: "var(--sp-3)", display: "block" }}>
|
||||||
|
<strong>{t("import.filterTitle")}</strong>
|
||||||
|
<p className="muted small">{t("import.filterHint")}</p>
|
||||||
|
<div className="map-grid">
|
||||||
|
<label>
|
||||||
|
<span>{t("import.filterColumn")}</span>
|
||||||
|
<select value={config.filter_column ?? ""}
|
||||||
|
onChange={(e) => setCfg({
|
||||||
|
filter_column: e.target.value === "" ? null : Number(e.target.value),
|
||||||
|
filter_value: "",
|
||||||
|
})}>
|
||||||
|
<option value="">{t("import.filterNone")}</option>
|
||||||
|
{filterSpalten.map((c) => <option key={c.i} value={c.i}>{c.label}</option>)}
|
||||||
|
</select>
|
||||||
|
</label>
|
||||||
|
<label>
|
||||||
|
<span>{t("import.filterValue")}</span>
|
||||||
|
<select value={config.filter_value}
|
||||||
|
disabled={config.filter_column == null}
|
||||||
|
onChange={(e) => setCfg({ filter_value: e.target.value })}>
|
||||||
|
<option value="">{t("import.filterNone")}</option>
|
||||||
|
{(raw?.filter_values?.[String(config.filter_column)] || []).map((w) => (
|
||||||
|
<option key={w.value} value={w.value}>
|
||||||
|
{t("import.filterValueOption", { value: w.value, count: w.count })}
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
<details className="import-more">
|
<details className="import-more">
|
||||||
<summary className="muted small">{t("import.moreColumns")}</summary>
|
<summary className="muted small">{t("import.moreColumns")}</summary>
|
||||||
<p className="muted small">{t("import.ibanHint")}</p>
|
<p className="muted small">{t("import.ibanHint")}</p>
|
||||||
@@ -542,23 +584,6 @@ export default function Import() {
|
|||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
<p className="muted small">{t("import.extraColsHint")}</p>
|
<p className="muted small">{t("import.extraColsHint")}</p>
|
||||||
<div className="map-grid">
|
|
||||||
<label>
|
|
||||||
<span>{t("import.filterColumn")}</span>
|
|
||||||
<select value={config.filter_column ?? ""}
|
|
||||||
onChange={(e) => setCfg({ filter_column: e.target.value === "" ? null : Number(e.target.value) })}>
|
|
||||||
<option value="">{t("import.filterNone")}</option>
|
|
||||||
{colOptions.map((c) => <option key={c.i} value={c.i}>{c.label}</option>)}
|
|
||||||
</select>
|
|
||||||
</label>
|
|
||||||
<label>
|
|
||||||
<span>{t("import.filterValue")}</span>
|
|
||||||
<input value={config.filter_value}
|
|
||||||
placeholder={t("import.filterValuePlaceholder")}
|
|
||||||
onChange={(e) => setCfg({ filter_value: e.target.value })} />
|
|
||||||
</label>
|
|
||||||
</div>
|
|
||||||
<p className="muted small">{t("import.filterHint")}</p>
|
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
<div className="field-inline" style={{ marginTop: "var(--sp-3)" }}>
|
<div className="field-inline" style={{ marginTop: "var(--sp-3)" }}>
|
||||||
|
|||||||
Reference in New Issue
Block a user