fix: restore hidden budget categories during seed
This commit is contained in:
+45
-11
@@ -204,6 +204,44 @@ def _deactivate_placeholder_categories() -> None:
|
||||
category.community_account_id = None
|
||||
|
||||
|
||||
def _restore_existing_standard_structure() -> None:
|
||||
for account_slug, account_data in ACCOUNT_TREE.items():
|
||||
account = Account.query.filter_by(slug=account_slug).first()
|
||||
if account is None:
|
||||
continue
|
||||
for category_slug, entries in account_data["categories"].items():
|
||||
category = Category.query.filter_by(account_id=account.id, slug=category_slug).first()
|
||||
legacy_slug = LEGACY_CATEGORY_SLUGS.get((account_slug, category_slug))
|
||||
if category is None and legacy_slug:
|
||||
category = Category.query.filter_by(account_id=account.id, slug=legacy_slug).first()
|
||||
if category is None:
|
||||
continue
|
||||
category.is_active = True
|
||||
for entry_name in entries:
|
||||
entry_slug = slugify(entry_name)
|
||||
entry = Entry.query.filter_by(category_id=category.id, slug=entry_slug).first()
|
||||
legacy_entry_name = LEGACY_ENTRY_NAMES.get((account_slug, category_slug, entry_name))
|
||||
if entry is None and legacy_entry_name:
|
||||
entry = Entry.query.filter_by(
|
||||
category_id=category.id,
|
||||
slug=slugify(legacy_entry_name),
|
||||
).first()
|
||||
if entry is not None:
|
||||
entry.is_active = True
|
||||
|
||||
|
||||
def _restore_existing_budget_visibility() -> None:
|
||||
gemeinschaft = Account.query.filter_by(slug="gemeinschaftskonto").first()
|
||||
if gemeinschaft is None:
|
||||
return
|
||||
for category in gemeinschaft.categories:
|
||||
if category.is_active:
|
||||
continue
|
||||
active_entries = [entry for entry in category.entries if entry.is_active]
|
||||
if active_entries:
|
||||
category.is_active = True
|
||||
|
||||
|
||||
def seed_data(include_example_entries: bool = False) -> None:
|
||||
# Basisdaten nur für die fachliche Grundstruktur, ohne Demo-Benutzer,
|
||||
# Beispiel-Personen oder vorausgefüllte Monatsdaten.
|
||||
@@ -393,18 +431,14 @@ def seed_data(include_example_entries: bool = False) -> None:
|
||||
"Person 1",
|
||||
"Person 2",
|
||||
}
|
||||
for category in gemeinschaft.categories:
|
||||
if category.slug not in ACCOUNT_TREE["gemeinschaftskonto"]["categories"]:
|
||||
category.is_active = False
|
||||
elif category.community_account_id is None:
|
||||
category.community_account_id = community_accounts["hauptkonto"].id
|
||||
else:
|
||||
_deactivate_placeholder_categories()
|
||||
_deactivate_placeholder_entries()
|
||||
for category in gemeinschaft.categories:
|
||||
if category.slug not in ACCOUNT_TREE["gemeinschaftskonto"]["categories"]:
|
||||
category.is_active = False
|
||||
elif category.community_account_id is None:
|
||||
category.community_account_id = community_accounts["hauptkonto"].id
|
||||
|
||||
if not include_example_entries:
|
||||
_deactivate_placeholder_categories()
|
||||
_deactivate_placeholder_entries()
|
||||
_restore_existing_standard_structure()
|
||||
_restore_existing_budget_visibility()
|
||||
|
||||
db.session.commit()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user