From 4834cb1c7364cc437a9affb840d1a10a55378c0d Mon Sep 17 00:00:00 2001 From: NguyenND Date: Wed, 3 Jun 2026 14:50:36 -0400 Subject: [PATCH] 06/03 Optimize codes, Schwab account --- app/services/investment_service.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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()