From d4183f30e6a0aad4045754a646d3d569d2ec206f Mon Sep 17 00:00:00 2001
From: Junwei Zhao
Date: Sat, 25 Apr 2026 10:40:46 +1000
Subject: [PATCH] fix: show live values and correct change% on invest dashboard
cards
---
invest/template_views.py | 16 ++++++++++++----
invest/templates/invest/dashboard.html | 4 ++--
2 files changed, 14 insertions(+), 6 deletions(-)
diff --git a/invest/template_views.py b/invest/template_views.py
index b93033f..e435a27 100644
--- a/invest/template_views.py
+++ b/invest/template_views.py
@@ -20,13 +20,21 @@ def dashboard(request):
fy_label = f"FY {str(fy_start)[2:]}-{str(fy_start + 1)[2:]}"
all_holdings = get_all_holdings()
- # Merge snapshot data (value, change, change_pct) into each holdings group
+ # Merge snapshot data into each holdings group.
+ # Change is computed as (live total – last snapshot), so the card header and
+ # the change line are always consistent with the live holdings table.
rows_by_id = {row['portfolio'].id: row for row in overview.get('portfolio_rows', [])}
for group in all_holdings:
row = rows_by_id.get(group['portfolio'].id, {})
- group['this_week_value'] = row.get('this_week_value')
- group['change'] = row.get('change')
- group['change_pct'] = row.get('change_pct')
+ group['last_snapshot_value'] = row.get('this_week_value')
+ live_val = group['total_value']
+ last_val = group['last_snapshot_value']
+ if live_val is not None and last_val and last_val > 0:
+ group['change'] = live_val - last_val
+ group['change_pct'] = round(((live_val - last_val) / last_val) * 100, 2)
+ else:
+ group['change'] = None
+ group['change_pct'] = None
group['position_count'] = row.get('position_count', len(group['holdings']))
recent_transactions = (
diff --git a/invest/templates/invest/dashboard.html b/invest/templates/invest/dashboard.html
index 9b1ef22..f9119d9 100644
--- a/invest/templates/invest/dashboard.html
+++ b/invest/templates/invest/dashboard.html
@@ -102,12 +102,12 @@
{{ group.position_count }} position{{ group.position_count|pluralize }}
- {% if overview.this_week_date %}· Last updated {{ overview.this_week_date|date:"j M Y" }}{% endif %}
+ {% if overview.this_week_date %}· Snapshot {{ overview.this_week_date|date:"j M Y" }}{% endif %}
- {% if group.this_week_value is not None %}${{ group.this_week_value|floatformat:0 }}{% else %}—{% endif %}
+ {% if group.total_value %}${{ group.total_value|floatformat:0 }}{% else %}—{% endif %}
{% if group.change is not None %}