fix: show live values and correct change% on invest dashboard cards

This commit is contained in:
2026-04-25 10:40:46 +10:00
parent eb02eca719
commit d4183f30e6
2 changed files with 14 additions and 6 deletions
+12 -4
View File
@@ -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 = (
+2 -2
View File
@@ -102,12 +102,12 @@
</p>
<p class="text-xs text-stone-400 mt-0.5">
{{ 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 %}
</p>
</div>
<div class="text-right">
<p class="font-bold text-stone-900 text-sm">
{% if group.this_week_value is not None %}${{ group.this_week_value|floatformat:0 }}{% else %}<span class="text-stone-300"></span>{% endif %}
{% if group.total_value %}${{ group.total_value|floatformat:0 }}{% else %}<span class="text-stone-300"></span>{% endif %}
</p>
{% if group.change is not None %}
<p class="text-xs font-medium mt-0.5 {% if group.change >= 0 %}text-green-700{% else %}text-red-600{% endif %}">