feat: Eine Ausgabe, die kein Verlust ist
Sparen zaehlt im Budget wie eine Ausgabe – zu Recht, das Geld ist diesen Monat gebunden. Es stand danach aber in Rot da, und wer tausend zuruecklegte statt achthundert, bekam eine Warnung fuer etwas Gutes. Ein Haken an der Kategorie stellt das ab. Zwei Folgen: Der Betrag steht neutral. NICHT gruen: Gruen heisst in Certain ueberall "Geld kommt rein", und CHF 1'010 in Gruen liest sich als Einnahme. Grau sagt genau das Richtige – kein Verlust, kein Gewinn. Und mehr als geplant ist keine Ueberschreitung mehr. Das gilt auch eine Ebene hoeher: Eine Gruppe misst sich an dem, was WIRKLICH zu viel war. Sonst faerbt sich "Finanzen" rot, weil jemand gespart hat, und die echte Ueberschreitung daneben faellt nicht mehr auf. Angezeigt werden weiter die vollen Summen; nur das Urteil laesst das Sparen aus. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
15c2a164ec
commit
ff621984dc
@@ -108,6 +108,15 @@ def _units(groups: list[CategoryGroup], by_category: bool):
|
||||
yield (g.name, g.color, [c.id for c in g.categories if not c.is_archived])
|
||||
|
||||
|
||||
def _kein_verlust(groups: list[CategoryGroup]) -> set[int]:
|
||||
"""Kategorien, deren Ausgabe kein Verlust ist (Sparen, Ruecklagen).
|
||||
|
||||
Ihre Betraege stehen neutral statt rot, und mehr als geplant ist bei ihnen
|
||||
keine Warnung.
|
||||
"""
|
||||
return {c.id for g in groups for c in g.categories if c.spending_is_good}
|
||||
|
||||
|
||||
@router.get("/budget-donut")
|
||||
def budget_donut(
|
||||
group_by: str = Query(default="group"),
|
||||
@@ -163,15 +172,22 @@ def expense_share(
|
||||
|
||||
# Als Liste: ``_units`` ist ein Generator, und er wird hier zweimal
|
||||
# gebraucht – beim zweiten Mal waere er leer und das Geplante 0.
|
||||
einheiten = list(_units(_expense_groups(db, user), by_category))
|
||||
gruppen = _expense_groups(db, user)
|
||||
gut = _kein_verlust(gruppen)
|
||||
einheiten = list(_units(gruppen, by_category))
|
||||
rows = []
|
||||
for name, color, ids in einheiten:
|
||||
val = sum(actual.get(i, 0) for i in ids)
|
||||
if val > 0:
|
||||
geplant = sum(planned.get(i, 0) for i in ids)
|
||||
# Ueberschritten ist die Zeile an dem, was WIRKLICH zu viel war –
|
||||
# das Sparen bleibt beim Urteil draussen, nicht beim Betrag.
|
||||
echt_geplant = sum(planned.get(i, 0) for i in ids if i not in gut)
|
||||
echt_ist = sum(actual.get(i, 0) for i in ids if i not in gut)
|
||||
rows.append({"name": name, "color": color, "amount": val,
|
||||
"planned": geplant,
|
||||
"over": geplant > 0 and val > geplant,
|
||||
"over": echt_geplant > 0 and echt_ist > echt_geplant,
|
||||
"good": bool(ids) and all(i in gut for i in ids),
|
||||
# Womit sich die Zeile aufschluesseln laesst.
|
||||
"ids": list(ids)})
|
||||
rows.sort(key=lambda r: r["amount"], reverse=True)
|
||||
@@ -251,12 +267,18 @@ def budget_progress(
|
||||
planned = budget.effective_planned(db, user, label)
|
||||
actual = budget.actual_expense_by_category(db, user, label, start, end, base)
|
||||
by_category = group_by == "category"
|
||||
gruppen = _expense_groups(db, user)
|
||||
gut = _kein_verlust(gruppen)
|
||||
rows = []
|
||||
for name, color, ids in _units(_expense_groups(db, user), by_category):
|
||||
for name, color, ids in _units(gruppen, by_category):
|
||||
gp = sum(planned.get(i, 0) for i in ids)
|
||||
ga = sum(actual.get(i, 0) for i in ids)
|
||||
if gp > 0 or ga > 0:
|
||||
rows.append({"name": name, "color": color, "planned": gp, "actual": ga, "over": ga > gp})
|
||||
echt_geplant = sum(planned.get(i, 0) for i in ids if i not in gut)
|
||||
echt_ist = sum(actual.get(i, 0) for i in ids if i not in gut)
|
||||
rows.append({"name": name, "color": color, "planned": gp, "actual": ga,
|
||||
"over": echt_ist > echt_geplant,
|
||||
"good": bool(ids) and all(i in gut for i in ids)})
|
||||
return {"rows": rows, "currency": base, "label": label,
|
||||
"group_by": "category" if by_category else "group"}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user