fix: start with empty budgets and savings categories

This commit is contained in:
2026-04-21 21:37:04 +02:00
parent 35af65dd25
commit 8bf37c82b6
3 changed files with 123 additions and 86 deletions
+29 -38
View File
@@ -266,7 +266,11 @@ def detail(label: str):
)
month_values = {item.entry_id: item for item in month.entry_values}
distribution_bucket = {
"account": None,
"account": type(
"SyntheticAccount",
(),
{"name": "Sparen & Verteilung", "slug": "sparen-und-verteilung"},
)(),
"categories": [],
"total": Decimal("0.00"),
}
@@ -337,12 +341,6 @@ def detail(label: str):
}
)
if account.slug in {"sparen", "urlaub", "freizeit"}:
if distribution_bucket["account"] is None:
distribution_bucket["account"] = type(
"SyntheticAccount",
(),
{"name": "Sparen & Verteilung", "slug": "sparen-und-verteilung"},
)()
distribution_bucket["categories"].append(
{
"category": type(
@@ -372,12 +370,6 @@ def detail(label: str):
distribution_bucket["total"] += account_total
continue
if account.slug in {"persoenlich-flo", "persoenlich-desi"}:
if distribution_bucket["account"] is None:
distribution_bucket["account"] = type(
"SyntheticAccount",
(),
{"name": "Sparen & Verteilung", "slug": "sparen-und-verteilung"},
)()
personal_category = next(
(item for item in distribution_bucket["categories"] if item.get("is_personal_split")),
None,
@@ -412,32 +404,31 @@ def detail(label: str):
planning_accounts.append(
{"account": account, "categories": category_cards, "total": account_total}
)
if distribution_bucket["account"] is not None:
personal_category = next(
(item for item in distribution_bucket["categories"] if item.get("is_personal_split")),
None,
personal_category = next(
(item for item in distribution_bucket["categories"] if item.get("is_personal_split")),
None,
)
if personal_category is not None:
personal_category["distribution_suggestion_total"] = max(
-summary.allocation_total,
summary.remainder,
)
if personal_category is not None:
personal_category["distribution_suggestion_total"] = max(
-summary.allocation_total,
summary.remainder,
)
personal_category["distribution_items"] = [
{
"slug": slug,
"label": personal_label_map.get(slug, slug),
"allocation": allocations_by_slug.get(slug),
"suggestion": suggestions_by_slug.get(slug),
"remaining_amount": max(
Decimal("0.00"),
to_decimal(suggestions_by_slug.get(slug).suggested_amount if suggestions_by_slug.get(slug) else 0)
- to_decimal(allocations_by_slug.get(slug).amount if allocations_by_slug.get(slug) else 0),
),
"auto_amount": to_decimal(allocations_by_slug.get(slug).amount if allocations_by_slug.get(slug) else 0),
}
for slug in ("persoenlich-flo", "persoenlich-desi")
]
planning_accounts.insert(0, distribution_bucket)
personal_category["distribution_items"] = [
{
"slug": slug,
"label": personal_label_map.get(slug, slug),
"allocation": allocations_by_slug.get(slug),
"suggestion": suggestions_by_slug.get(slug),
"remaining_amount": max(
Decimal("0.00"),
to_decimal(suggestions_by_slug.get(slug).suggested_amount if suggestions_by_slug.get(slug) else 0)
- to_decimal(allocations_by_slug.get(slug).amount if allocations_by_slug.get(slug) else 0),
),
"auto_amount": to_decimal(allocations_by_slug.get(slug).amount if allocations_by_slug.get(slug) else 0),
}
for slug in ("persoenlich-flo", "persoenlich-desi")
]
planning_accounts.insert(0, distribution_bucket)
previous_month = month_service.previous_month(month.year, month.month)
budget_categories = db.session.scalars(
select(Category)