diff --git a/crud.py b/crud.py index 75b1fc4..be8f830 100644 --- a/crud.py +++ b/crud.py @@ -464,8 +464,15 @@ async def get_all_user_balances() -> list[UserBalance]: balance = await get_account_balance(account.id) # Get all entry lines for this account to calculate fiat balances + # Only include cleared entries (exclude pending/flagged/voided) entry_lines = await db.fetchall( - "SELECT * FROM entry_lines WHERE account_id = :account_id", + """ + SELECT el.* + FROM entry_lines el + JOIN journal_entries je ON el.journal_entry_id = je.id + WHERE el.account_id = :account_id + AND je.flag = '*' + """, {"account_id": account.id}, )