fix: keep fresh installs free of placeholder entries
This commit is contained in:
+36
-2
@@ -130,6 +130,13 @@ ENTRY_TARGET_CATEGORY = {
|
||||
"Kreditrate 2": "finanzen",
|
||||
}
|
||||
|
||||
EXAMPLE_ENTRY_NAMES = {
|
||||
entry_name
|
||||
for account_data in ACCOUNT_TREE.values()
|
||||
for entries in account_data["categories"].values()
|
||||
for entry_name in entries
|
||||
}
|
||||
|
||||
|
||||
def slugify(value: str) -> str:
|
||||
return (
|
||||
@@ -143,7 +150,29 @@ def slugify(value: str) -> str:
|
||||
)
|
||||
|
||||
|
||||
def seed_data() -> None:
|
||||
def _deactivate_placeholder_entries() -> None:
|
||||
example_entries = (
|
||||
Entry.query.filter(Entry.name.in_(sorted(EXAMPLE_ENTRY_NAMES)), Entry.is_active.is_(True)).all()
|
||||
)
|
||||
for entry in example_entries:
|
||||
has_user_data = False
|
||||
for value in entry.monthly_values:
|
||||
if (
|
||||
to_decimal(value.planned_amount) != Decimal("0.00")
|
||||
or value.note
|
||||
or value.created_by is not None
|
||||
or value.updated_by is not None
|
||||
):
|
||||
has_user_data = True
|
||||
break
|
||||
if entry.share_rules:
|
||||
has_user_data = True
|
||||
if has_user_data:
|
||||
continue
|
||||
entry.is_active = False
|
||||
|
||||
|
||||
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.
|
||||
community_accounts = {}
|
||||
@@ -225,6 +254,8 @@ def seed_data() -> None:
|
||||
category.community_account_id = community_accounts["hauptkonto"].id
|
||||
account_categories[account_slug][category_slug] = category
|
||||
category_sort += 1
|
||||
if not include_example_entries:
|
||||
continue
|
||||
for index, entry_name in enumerate(entries, start=1):
|
||||
default_amount = Decimal("0.00")
|
||||
if entry_name == "Miete":
|
||||
@@ -293,6 +324,7 @@ def seed_data() -> None:
|
||||
|
||||
gemeinschaft = Account.query.filter_by(slug="gemeinschaftskonto").first()
|
||||
if gemeinschaft:
|
||||
if include_example_entries:
|
||||
target_categories = account_categories["gemeinschaftskonto"]
|
||||
with db.session.no_autoflush:
|
||||
for category in gemeinschaft.categories:
|
||||
@@ -329,6 +361,8 @@ def seed_data() -> None:
|
||||
"Person 1",
|
||||
"Person 2",
|
||||
}
|
||||
else:
|
||||
_deactivate_placeholder_entries()
|
||||
for category in gemeinschaft.categories:
|
||||
if category.slug not in ACCOUNT_TREE["gemeinschaftskonto"]["categories"]:
|
||||
category.is_active = False
|
||||
@@ -342,7 +376,7 @@ def seed_demo_data() -> None:
|
||||
from datetime import date
|
||||
from flask import current_app
|
||||
|
||||
seed_data()
|
||||
seed_data(include_example_entries=True)
|
||||
|
||||
admin = User.query.filter_by(username="admin").first()
|
||||
if admin is None:
|
||||
|
||||
Reference in New Issue
Block a user