Fix virtual parent detection by refreshing account list

Bug: Virtual intermediate parents weren't being created because
all_account_names was built from stale data (before Step 1 synced new accounts).

Example failure:
- Beancount has: Expenses:Supplies:Food, Expenses:Supplies:Kitchen
- Step 1 syncs these to Castle DB
- Step 3 checks if parent 'Expenses:Supplies' exists
- But checks against OLD account list (before Step 1)
- Doesn't find the children, so can't detect missing parent

Fix: Re-fetch accounts from database after Step 1 completes,
so all_account_names includes newly synced children.

🤖 Generated with Claude Code (https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
padreug 2025-11-11 02:53:41 +01:00
parent fa92295513
commit d255d7ddc9

View file

@ -233,7 +233,11 @@ async def sync_accounts_from_beancount(force_full_sync: bool = False) -> dict:
# Step 3: Auto-generate virtual intermediate parent accounts
# For each account in Beancount, check if all parent levels exist
# If not, create them as virtual accounts
all_account_names = set(castle_accounts_by_name.keys())
# IMPORTANT: Re-fetch accounts from DB after Step 1 added new accounts
# Otherwise we'll be checking against stale data and miss newly synced children
current_castle_accounts = await get_all_accounts(include_inactive=True)
all_account_names = {acc.name for acc in current_castle_accounts}
for bc_account in beancount_accounts:
account_name = bc_account["account"]