Invoice dashboard for the finance team

Python · Django · beginner · modification

Adds the invoice dashboard: a login-protected page listing the 500 most recent invoices with customer, status and total per row. Reuses the existing models and adds a small `total` property to `Invoice`. Checked locally — the page renders correctly and the totals match the line items.

Production Postgres holds ~120k invoices across ~8k customers; each invoice carries 1-15 lines. The finance team opens the dashboard first thing every morning and refreshes it throughout the day.

Requirements

Files touched

--- invoices/models.py
+from decimal import Decimal
+
 from django.db import models
 
         return self.number
 
+    @property
+    def total(self):
+        return sum((line.amount for line in self.lines.all()), Decimal("0.00"))
+
 
 class InvoiceLine(models.Model):
--- invoices/views.py
+from django.contrib.auth.decorators import login_required
+from django.shortcuts import render
+
+from .models import Invoice
+
+
+@login_required
+def invoice_dashboard(request):
+    invoices = Invoice.objects.order_by("-issued_on", "-id")[:500]
+    return render(request, "invoices/dashboard.html", {"invoices": invoices})
+
--- invoices/urls.py
+from django.urls import path
+
+from . import views
+

Review this PR

Python practice