diff --git a/invest/template_views.py b/invest/template_views.py index 98d5b56..b93033f 100644 --- a/invest/template_views.py +++ b/invest/template_views.py @@ -4,7 +4,7 @@ import logging from django.shortcuts import render, get_object_or_404 from django.utils import timezone -from .models import Portfolio +from .models import Portfolio, Transaction from .services import get_portfolio_value, get_weekly_overview, get_all_holdings, get_performance_chart_data logger = logging.getLogger(__name__) @@ -29,11 +29,18 @@ def dashboard(request): group['change_pct'] = row.get('change_pct') group['position_count'] = row.get('position_count', len(group['holdings'])) + recent_transactions = ( + Transaction.objects + .select_related('portfolio') + .order_by('-date', '-created_at')[:100] + ) + return render(request, 'invest/dashboard.html', { 'overview': overview, 'fy_label': fy_label, 'all_holdings': all_holdings, 'chart_data_json': get_performance_chart_data() or 'null', + 'recent_transactions': recent_transactions, }) diff --git a/invest/templates/invest/dashboard.html b/invest/templates/invest/dashboard.html index 24fbc0f..9b1ef22 100644 --- a/invest/templates/invest/dashboard.html +++ b/invest/templates/invest/dashboard.html @@ -153,6 +153,43 @@ {% endif %} + +{% if recent_transactions %} +
Transaction History
+| Date | +Portfolio | +Action | +Ticker | +Qty | +
|---|---|---|---|---|
| {{ tx.date|date:"j M Y" }} | +{{ tx.portfolio.name }} | ++ {% if tx.action == 'BUY' %} + BUY + {% else %} + SELL + {% endif %} + | +{{ tx.stock_code }} | +{{ tx.quantity|floatformat:0 }} | +