diff --git a/app/services/investment_service.py b/app/services/investment_service.py index bd13255..154a32d 100644 --- a/app/services/investment_service.py +++ b/app/services/investment_service.py @@ -329,8 +329,10 @@ def get_portfolio_summary(): Also returns per-account groups for investments that are linked to an account (e.g. separate Schwab Individual vs Roth IRA views). """ + from sqlalchemy import func investments = Investment.query.filter_by(is_active=True).order_by( - Investment.account_id.asc().nullslast(), + func.isnull(Investment.account_id), # 0 for linked, 1 for NULL → linked first + Investment.account_id, Investment.asset_type, Investment.asset_name, ).all()