fix: Anfangssaldo gilt ab dem Stichtag

Der Stichtag eines Kontos wurde gespeichert und angezeigt, von der
Saldo-Berechnung aber ignoriert: sie addierte jede Buchung des Kontos,
auch die aus der Zeit vor dem Stichtag. Damit lief jeder Saldo um die
gesamte Vorgeschichte daneben.

Der Anfangssaldo beschreibt jetzt den Stand am ENDE des Stichtags – so
steht er auf dem Auszug. Buchungen bis einschliesslich dieses Tages
zaehlen nicht mehr zum Kontostand, bleiben aber in Liste und
Auswertungen. Beim Uebertrag wird jede Seite an ihrem eigenen Stichtag
gemessen; der Vermoegensverlauf folgt derselben Regel. Ohne Stichtag
zaehlt weiterhin alles.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Guido
2026-08-21 15:26:21 +02:00
co-authored by Claude Opus 5
parent d88efebfeb
commit 5dbfd6abc4
6 changed files with 116 additions and 31 deletions
+15 -10
View File
@@ -250,17 +250,22 @@ def net_worth(
opening_eur = sum(to_eur(a.opening_balance_cents, a.currency, a.opening_date or start) for a in accounts)
def zaehlt(acc: Account | None, on: date) -> bool:
"""Buchungen bis zum Stichtag stecken schon im Anfangssaldo."""
return acc is not None and (acc.opening_date is None or on > acc.opening_date)
def eur_effect(t: Transaction) -> int:
if t.type == TxnType.income:
return t.amount_eur_cents
if t.type == TxnType.expense:
return -t.amount_eur_cents
# Transfer: Netto-Effekt aufs Vermögen = EUR-Wert Zugang - EUR-Wert Abgang.
to_acc = acc_by_id.get(t.to_account_id) if t.to_account_id else None
if to_acc is None:
return 0 # Zielkonto archiviert/gelöscht: ignorieren
credited = t.to_amount_cents if t.to_amount_cents is not None else t.amount_cents
return to_eur(credited, to_acc.currency, t.date) - t.amount_eur_cents
# Jede Seite wird für sich geprüft: Der Stichtag des Quellkontos kann
# anders liegen als der des Zielkontos.
effekt = 0
if zaehlt(acc_by_id.get(t.account_id), t.date):
effekt += t.amount_eur_cents if t.type == TxnType.income else -t.amount_eur_cents
if t.type == TxnType.transfer:
to_acc = acc_by_id.get(t.to_account_id) if t.to_account_id else None
if zaehlt(to_acc, t.date):
credited = t.to_amount_cents if t.to_amount_cents is not None else t.amount_cents
effekt += to_eur(credited, to_acc.currency, t.date)
return effekt
txns = db.query(Transaction).filter(
Transaction.owner_id == user.id, Transaction.account_id.in_(list(acc_by_id.keys()) or [0])