Updates default chart of accounts

Expands the default chart of accounts with a more
detailed hierarchical structure. This includes new
accounts for fixed assets, livestock, equity
contributions, and detailed expense categories.
The migration script only adds accounts that don't
already exist, ensuring a smooth update process.
This commit is contained in:
padreug 2025-11-07 22:24:23 +01:00
parent 6f62c52c68
commit 88aaf0e28e
3 changed files with 89 additions and 29 deletions

View file

@ -452,3 +452,37 @@ async def m011_account_permissions(db):
WHERE expires_at IS NOT NULL;
"""
)
async def m012_update_default_accounts(db):
"""
Update default chart of accounts to include more detailed hierarchical structure.
Adds new accounts for fixed assets, livestock, equity contributions, and detailed expenses.
Only adds accounts that don't already exist.
"""
import uuid
from .account_utils import DEFAULT_HIERARCHICAL_ACCOUNTS
for name, account_type, description in DEFAULT_HIERARCHICAL_ACCOUNTS:
# Check if account already exists
existing = await db.fetchone(
"""
SELECT id FROM accounts WHERE name = :name
""",
{"name": name}
)
if not existing:
# Create new account
await db.execute(
f"""
INSERT INTO accounts (id, name, account_type, description, created_at)
VALUES (:id, :name, :type, :description, {db.timestamp_now})
""",
{
"id": str(uuid.uuid4()),
"name": name,
"type": account_type.value,
"description": description
}
)