feat: Diagnose zeigt Stichtag und Beispieltexte je Übertrag

Der Stichtag eines Kontos wird von der Saldo-Berechnung ignoriert – das
Skript weist jetzt aus, wie viel aus Buchungen bis zum Stichtag stammt
und trotzdem mitzählt. Die Übertrags-Matrix nennt dazu Beispieltexte,
Erkennungstexte der Konten und Transfer-Schlagwörter, damit sich ein
falscher Übertrag seinem Auslöser zuordnen lässt.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Guido
2026-08-21 15:22:59 +02:00
co-authored by Claude Opus 5
parent e2387102c1
commit d88efebfeb
2 changed files with 44 additions and 2 deletions
+20 -2
View File
@@ -26,7 +26,7 @@ def geld(c, w=""):
print(f"Datenbank: {DB}\n")
for a in con.execute("SELECT id, name, currency, opening_balance_cents FROM accounts "
for a in con.execute("SELECT id, name, currency, opening_balance_cents, opening_date FROM accounts "
"WHERE is_archived = 0 ORDER BY position, id"):
ein = eins("SELECT SUM(amount_cents) FROM transactions WHERE account_id=? AND type='income'", a["id"])
aus = eins("SELECT SUM(amount_cents) FROM transactions WHERE account_id=? AND type='expense'", a["id"])
@@ -38,7 +38,9 @@ for a in con.execute("SELECT id, name, currency, opening_balance_cents FROM acco
spanne = con.execute("SELECT MIN(date), MAX(date) FROM transactions WHERE account_id=?", (a["id"],)).fetchone()
print(f"=== {a['name']} ({a['currency']}, id {a['id']}) ===")
print(f" Anfangssaldo {geld(a['opening_balance_cents']):>14}")
stichtag = a["opening_date"]
print(f" Anfangssaldo {geld(a['opening_balance_cents']):>14}"
f" Stichtag: {stichtag or '– keiner –'}")
print(f" + Einnahmen {geld(ein):>14}")
print(f" - Ausgaben {geld(aus):>14}")
print(f" - Transfers raus {geld(raus):>14}")
@@ -46,6 +48,22 @@ for a in con.execute("SELECT id, name, currency, opening_balance_cents FROM acco
print(f" = SALDO {geld(saldo, a['currency']):>14}")
print(f" {anz} Buchungen, {spanne[0] or '–'} bis {spanne[1] or '–'}")
# Der Stichtag wird von der Saldo-Berechnung derzeit ignoriert: sie addiert
# ALLE Buchungen. Gemeint ist aber "an diesem Tag stand so viel drauf", also
# dürften nur spätere Buchungen zählen. Hier steht, was das ausmacht.
if stichtag:
vor = (eins("SELECT SUM(amount_cents) FROM transactions WHERE account_id=? "
"AND type='income' AND date <= ?", a["id"], stichtag)
- eins("SELECT SUM(amount_cents) FROM transactions WHERE account_id=? "
"AND type='expense' AND date <= ?", a["id"], stichtag)
- eins("SELECT SUM(amount_cents) FROM transactions WHERE account_id=? "
"AND type='transfer' AND date <= ?", a["id"], stichtag)
+ eins("SELECT SUM(COALESCE(to_amount_cents, amount_cents)) FROM transactions "
"WHERE to_account_id=? AND type='transfer' AND date <= ?", a["id"], stichtag))
if vor:
print(f" ACHTUNG: {geld(vor)} stammt aus Buchungen BIS zum Stichtag und wird")
print(f" trotzdem mitgezählt. Ohne sie: {geld(saldo - vor, a['currency'])}")
# Doppelte Auszüge erkennen: gleicher Dateiname mehrfach gebucht.
batches = con.execute(
"SELECT filename, status, imported_count, created_at FROM import_batches "