fix: keep savings accounts editable without target flag
This commit is contained in:
+15
-11
@@ -177,6 +177,13 @@ def _community_account_totals(month, previous_month, community_accounts, budget_
|
||||
return cards
|
||||
|
||||
|
||||
def _resolve_distribution_direct_entry(entry_rows: list[dict]) -> dict | None:
|
||||
return next(
|
||||
(entry_row for entry_row in entry_rows if entry_row["entry"].is_allocation_target),
|
||||
entry_rows[0] if entry_rows else None,
|
||||
)
|
||||
|
||||
|
||||
def _distribution_hint_map(allocation_service, month, summary, allocations_by_slug, suggestions_by_slug) -> dict[str, dict]:
|
||||
result = {}
|
||||
return {
|
||||
@@ -340,7 +347,9 @@ def detail(label: str):
|
||||
"distribution_kind": "single" if account.slug in {"sparen", "urlaub", "freizeit"} else None,
|
||||
"distribution_suggestion_total": suggestion_total,
|
||||
"distribution_hint": distribution_hints.get(account.slug),
|
||||
"direct_entry": next(
|
||||
"direct_entry": _resolve_distribution_direct_entry(entry_rows)
|
||||
if account.slug in {"sparen", "urlaub", "freizeit"}
|
||||
else next(
|
||||
(entry_row for entry_row in entry_rows if entry_row["entry"].is_allocation_target),
|
||||
None,
|
||||
),
|
||||
@@ -348,6 +357,8 @@ def detail(label: str):
|
||||
}
|
||||
)
|
||||
if account.slug in {"sparen", "urlaub", "freizeit"}:
|
||||
flattened_entries = [entry for category_card in category_cards for entry in category_card["entries"]]
|
||||
direct_entry = _resolve_distribution_direct_entry(flattened_entries)
|
||||
distribution_bucket["categories"].append(
|
||||
{
|
||||
"category": type(
|
||||
@@ -355,7 +366,7 @@ def detail(label: str):
|
||||
(),
|
||||
{"id": account.id * -100, "name": account.name, "account_id": account.id},
|
||||
)(),
|
||||
"entries": [entry for category_card in category_cards for entry in category_card["entries"]],
|
||||
"entries": flattened_entries,
|
||||
"total": account_total,
|
||||
"entry_count": sum(category_card["entry_count"] for category_card in category_cards),
|
||||
"dialog_id": f"distribution-dialog-{account.slug}",
|
||||
@@ -363,15 +374,8 @@ def detail(label: str):
|
||||
"distribution_suggestion_total": distribution_hints.get(account.slug, {}).get("remaining_amount", Decimal("0.00")),
|
||||
"distribution_hint": distribution_hints.get(account.slug),
|
||||
"distribution_account_slug": account.slug,
|
||||
"direct_entry": next(
|
||||
(
|
||||
category_card.get("direct_entry")
|
||||
for category_card in category_cards
|
||||
if category_card.get("direct_entry") is not None
|
||||
),
|
||||
None,
|
||||
),
|
||||
"allow_new_entries": False,
|
||||
"direct_entry": direct_entry,
|
||||
"allow_new_entries": direct_entry is None,
|
||||
}
|
||||
)
|
||||
distribution_bucket["total"] += account_total
|
||||
|
||||
@@ -101,6 +101,19 @@ def test_distribution_dialog_shows_direct_budget_form(logged_in_client):
|
||||
assert b"Sparkonto" in response.data
|
||||
|
||||
|
||||
def test_distribution_dialog_keeps_direct_budget_form_when_target_flag_is_missing(logged_in_client):
|
||||
month = Month.query.filter_by(label="2026-04").first()
|
||||
sparen_value = next(item for item in month.entry_values if item.entry.name == "Sparziel")
|
||||
sparen_value.entry.is_allocation_target = False
|
||||
db.session.commit()
|
||||
|
||||
response = logged_in_client.get("/planning/2026-04")
|
||||
|
||||
assert response.status_code == 200
|
||||
assert b"Budget direkt anpassen" in response.data
|
||||
assert b"Monatliches Budget" in response.data
|
||||
|
||||
|
||||
def test_planning_shows_budgets_and_community_accounts(logged_in_client):
|
||||
response = logged_in_client.get("/planning/2026-04")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user