diff --git a/account_utils.py b/account_utils.py index 8eba3e0..ec756ad 100644 --- a/account_utils.py +++ b/account_utils.py @@ -191,7 +191,6 @@ def migrate_account_name(old_name: str, account_type: AccountType) -> str: DEFAULT_HIERARCHICAL_ACCOUNTS = [ # Assets ("Assets:Bank", AccountType.ASSET, "Bank account"), - ("Assets:Bitcoin", AccountType.ASSET, "Bitcoin holdings"), ("Assets:Bitcoin:Lightning", AccountType.ASSET, "Lightning Network balance"), ("Assets:Bitcoin:OnChain", AccountType.ASSET, "On-chain Bitcoin wallet"), ("Assets:Cash", AccountType.ASSET, "Cash on hand"), @@ -207,8 +206,8 @@ DEFAULT_HIERARCHICAL_ACCOUNTS = [ # Liabilities ("Liabilities:Payable", AccountType.LIABILITY, "Money owed by the Castle"), - # Equity - ("Equity", AccountType.EQUITY, "Owner's equity and member contributions"), + # Equity - User equity accounts created dynamically as Equity:User-{user_id} + # No parent "Equity" account needed - hierarchy is implicit in the name # Revenue (Income in Beancount terminology) ("Income:Accommodation:Guests", AccountType.REVENUE, "Revenue from guest accommodation"), diff --git a/migrations.py b/migrations.py index a170a73..cf4222f 100644 --- a/migrations.py +++ b/migrations.py @@ -486,3 +486,33 @@ async def m012_update_default_accounts(db): "description": description } ) + + +async def m013_remove_parent_only_accounts(db): + """ + Remove parent-only accounts from the database. + + Since Castle doesn't interface directly with Beancount (only exports to it), + we don't need parent accounts that exist only for organizational hierarchy. + The hierarchy is implicit in the colon-separated account names. + + When exporting to Beancount, the parent accounts will be inferred from the + hierarchical naming (e.g., "Assets:Bitcoin:Lightning" implies "Assets:Bitcoin" exists). + + This keeps our database clean and prevents accidentally posting to parent accounts. + + Removes: + - Assets:Bitcoin (parent of Lightning and OnChain) + - Equity (parent of user equity accounts like Equity:User-xxx) + """ + # Remove Assets:Bitcoin (parent account) + await db.execute( + "DELETE FROM accounts WHERE name = :name", + {"name": "Assets:Bitcoin"} + ) + + # Remove Equity (parent account) + await db.execute( + "DELETE FROM accounts WHERE name = :name", + {"name": "Equity"} + )