feat: Vorschlaege buchen und Telefon-Dateien nur ablegen
Zwei Luecken geschlossen: Mail-Vorschlaege standen als "pending" im Eingang, aber es gab keinen Knopf zum Buchen – der Weg war hinten offen. Jetzt je Eintrag "Buchen" und ein "Alle buchen". Unklare bleiben liegen: Bei ihnen fehlt etwas oder die Erkennung war unsicher, die soll man ansehen statt im Stapel durchzuwinken. Der Auszug vom Telefon bucht nicht mehr sofort, sondern wird nur abgelegt. Am Telefon prueft man keine 500 Zeilen; die Datei wartet in der Import-Ansicht und laeuft dort durch die normale Vorschau mit Saldo-Abgleich, Zeilenfilter und Duplikatpruefung. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -399,3 +399,48 @@ def test_zuordnung_mit_waehrung_schlaegt_die_allgemeine(admin, monkeypatch):
|
||||
|
||||
treffer = [e for e in admin.get("/api/inbox").json() if e["amount_cents"] == -1200]
|
||||
assert treffer and treffer[0]["account_id"] == eur["id"]
|
||||
|
||||
|
||||
def test_mailvorschlag_wird_erst_auf_knopfdruck_gebucht(admin, fake_imap):
|
||||
"""Eine Mail bucht nie von selbst – aber sie muss sich buchen lassen."""
|
||||
konto = _konto(admin, name="Buchbar", opening_balance_cents=0)
|
||||
quelle = _postfach(admin)
|
||||
admin.post(f"/api/mail/sources/{quelle['id']}/senders", json={
|
||||
"from_contains": "raiffeisen", "account_id": konto["id"]})
|
||||
|
||||
roh = (MUSTER / "raiffeisen_zahlungsstatus.eml").read_bytes().replace(
|
||||
b"<raiffeisen-muster-1@", b"<buchbar-1@")
|
||||
import unittest.mock as _m
|
||||
with _m.patch.object(mail_import, "_verbinden", lambda q: FakeImap([roh])):
|
||||
admin.post(f"/api/mail/sources/{quelle['id']}/fetch")
|
||||
|
||||
eintrag = [e for e in admin.get("/api/inbox").json()
|
||||
if e["account_id"] == konto["id"]][0]
|
||||
assert eintrag["status"] == "pending"
|
||||
assert admin.get(f"/api/accounts/{konto['id']}").json()["balance_cents"] == 0
|
||||
|
||||
r = admin.post(f"/api/inbox/{eintrag['id']}/book")
|
||||
assert r.status_code == 200, r.text
|
||||
assert r.json()["status"] == "booked"
|
||||
assert admin.get(f"/api/accounts/{konto['id']}").json()["balance_cents"] == -1490
|
||||
|
||||
# Zweimal buchen darf den Saldo nicht verdoppeln.
|
||||
admin.post(f"/api/inbox/{eintrag['id']}/book")
|
||||
assert admin.get(f"/api/accounts/{konto['id']}").json()["balance_cents"] == -1490
|
||||
|
||||
|
||||
def test_unklare_vorschlaege_werden_nicht_mitgebucht(admin, fake_imap):
|
||||
"""Ohne Zielkonto oder mit unsicherer Erkennung: liegen lassen, nicht durchwinken."""
|
||||
quelle = _postfach(admin)
|
||||
admin.post(f"/api/mail/sources/{quelle['id']}/senders", json={"from_contains": "revolut"})
|
||||
roh = (MUSTER / "revolut_ueberweisung.eml").read_bytes().replace(
|
||||
b"<revolut-muster-1@", b"<unklar-bleibt@")
|
||||
import unittest.mock as _m
|
||||
with _m.patch.object(mail_import, "_verbinden", lambda q: FakeImap([roh])):
|
||||
admin.post(f"/api/mail/sources/{quelle['id']}/fetch")
|
||||
|
||||
unklare = [e for e in admin.get("/api/inbox").json() if e["status"] == "unclear"]
|
||||
assert unklare
|
||||
admin.post("/api/inbox/book-all")
|
||||
danach = admin.get("/api/inbox").json()
|
||||
assert all(e["status"] == "unclear" for e in danach if e["id"] == unklare[0]["id"])
|
||||
|
||||
+51
-49
@@ -249,55 +249,6 @@ def test_zwei_gleiche_zahlungen_verbrauchen_je_einen_eintrag(admin):
|
||||
assert sum(1 for r in v["rows"] if r["include"]) == 1
|
||||
|
||||
|
||||
def test_auszug_vom_telefon_nutzt_die_zuletzt_benutzte_vorlage(admin):
|
||||
"""Am Telefon kann man keine Spalten zuordnen. Also wird die Einstellung
|
||||
wiederverwendet, mit der dieses Konto zuletzt eingelesen wurde."""
|
||||
client = _fremd()
|
||||
konto = _konto(admin, name="Handykonto", currency="CHF")
|
||||
marke = _marke(admin, konto["id"])
|
||||
kopf = {"X-Certain-Token": marke["token"]}
|
||||
import io
|
||||
|
||||
csv_text = KOPF + "01.04.2026;-12,00;Bäckerei;Brot;\n02.04.2026;-8,00;Kiosk;Zeitung;\n"
|
||||
|
||||
# Ohne vorherigen Import am Rechner: klare Ansage statt Rätselraten.
|
||||
r = client.post("/api/quick/statement",
|
||||
files={"file": ("a.csv", io.BytesIO(csv_text.encode()), "text/csv")},
|
||||
data={"account_id": str(konto["id"])}, headers=kopf)
|
||||
assert r.status_code == 400
|
||||
assert "am Rechner" in r.json()["detail"]
|
||||
|
||||
# Einmal am Rechner einlesen legt die Einstellung fest.
|
||||
import json as _json
|
||||
vorlage = admin.post("/api/imports/templates", json={
|
||||
"name": "Handytest " + secrets.token_hex(3), "delimiter": ";", "decimal_sep": ",",
|
||||
"date_format": "%d.%m.%Y", "encoding": "utf-8", "has_header": True, "skip_rows": 0,
|
||||
"amount_mode": "signed",
|
||||
"column_map": {"date": 0, "amount": 1, "payee": 2, "purpose": 3},
|
||||
})
|
||||
assert vorlage.status_code == 201, vorlage.text
|
||||
v = _import(admin, konto["id"], csv_text)
|
||||
admin.post("/api/imports/commit", json={
|
||||
"account_id": konto["id"], "filename": "april.csv",
|
||||
"template_id": vorlage.json()["id"],
|
||||
"rows": [x for x in v["rows"] if x["include"]]})
|
||||
assert admin.get(f"/api/accounts/{konto['id']}").json()["balance_cents"] == 100000 - 2000
|
||||
|
||||
# Ab jetzt geht es vom Telefon: neue Zeilen kommen an, alte nicht doppelt.
|
||||
mehr = csv_text + "03.04.2026;-5,50;Coop;Milch;\n"
|
||||
r = client.post("/api/quick/statement",
|
||||
files={"file": ("april.csv", io.BytesIO(mehr.encode()), "text/csv")},
|
||||
data={"account_id": str(konto["id"])}, headers=kopf)
|
||||
assert r.status_code == 201, r.text
|
||||
assert r.json()["gebucht"] == 1
|
||||
assert r.json()["duplikate"] == 2
|
||||
assert admin.get(f"/api/accounts/{konto['id']}").json()["balance_cents"] == 100000 - 2550
|
||||
|
||||
# Und der Stapel steht im Verlauf, also mit einem Klick ruecknehmbar.
|
||||
stapel = admin.get("/api/imports/batches").json()
|
||||
assert any(b["filename"] == "april.csv" and b["imported_count"] == 1 for b in stapel)
|
||||
|
||||
|
||||
def test_auszug_vom_telefon_braucht_eine_gueltige_marke(admin):
|
||||
import io
|
||||
konto = _konto(admin, name="Fremdes Konto")
|
||||
@@ -305,3 +256,54 @@ def test_auszug_vom_telefon_braucht_eine_gueltige_marke(admin):
|
||||
files={"file": ("a.csv", io.BytesIO(b"x"), "text/csv")},
|
||||
data={"account_id": str(konto["id"])})
|
||||
assert r.status_code == 401
|
||||
|
||||
|
||||
def test_auszug_vom_telefon_wird_nur_abgelegt_nicht_gebucht(admin):
|
||||
"""Am Telefon prüft man keine 500 Zeilen. Die Datei wartet in Certain."""
|
||||
client = _fremd()
|
||||
konto = _konto(admin, name="Ablagekonto", currency="CHF")
|
||||
marke = _marke(admin, konto["id"])
|
||||
import io
|
||||
|
||||
csv_text = KOPF + "01.04.2026;-12,00;Bäckerei;Brot;\n"
|
||||
r = client.post("/api/quick/statement",
|
||||
files={"file": ("april.csv", io.BytesIO(csv_text.encode()), "text/csv")},
|
||||
data={"account_id": str(konto["id"])},
|
||||
headers={"X-Certain-Token": marke["token"]})
|
||||
assert r.status_code == 201, r.text
|
||||
assert "Empfangen" in r.json()["message"]
|
||||
# Nichts gebucht.
|
||||
assert admin.get(f"/api/accounts/{konto['id']}").json()["balance_cents"] == 100000
|
||||
|
||||
wartend = [u for u in admin.get("/api/imports/uploads").json()
|
||||
if u["account_id"] == konto["id"]]
|
||||
assert len(wartend) == 1
|
||||
assert wartend[0]["filename"] == "april.csv"
|
||||
|
||||
# Der Inhalt kommt unverändert zurück – die Import-Ansicht liest ihn wie
|
||||
# eine lokale Datei.
|
||||
inhalt = admin.get(f"/api/imports/uploads/{wartend[0]['id']}/content")
|
||||
assert inhalt.status_code == 200
|
||||
assert "Bäckerei" in inhalt.content.decode("utf-8")
|
||||
|
||||
assert admin.delete(f"/api/imports/uploads/{wartend[0]['id']}").status_code == 204
|
||||
assert not [u for u in admin.get("/api/imports/uploads").json()
|
||||
if u["id"] == wartend[0]["id"]]
|
||||
|
||||
|
||||
def test_leere_und_zu_grosse_dateien_werden_abgewiesen(admin):
|
||||
client = _fremd()
|
||||
konto = _konto(admin, name="Grenzkonto")
|
||||
marke = _marke(admin, konto["id"])
|
||||
kopf = {"X-Certain-Token": marke["token"]}
|
||||
import io
|
||||
|
||||
leer = client.post("/api/quick/statement",
|
||||
files={"file": ("leer.csv", io.BytesIO(b""), "text/csv")},
|
||||
data={"account_id": str(konto["id"])}, headers=kopf)
|
||||
assert leer.status_code == 400
|
||||
|
||||
riesig = client.post("/api/quick/statement",
|
||||
files={"file": ("gross.csv", io.BytesIO(b"x" * (6 * 1024 * 1024)), "text/csv")},
|
||||
data={"account_id": str(konto["id"])}, headers=kopf)
|
||||
assert riesig.status_code == 413
|
||||
|
||||
Reference in New Issue
Block a user