From 4dbe69574c2a9249418ffe7f168eeb8a62c23d74 2016-09-03 02:17:39 From: Christopher Neugebauer Date: 2016-09-03 02:17:39 Subject: [PATCH] Adds report that tracks the free money in the system Fixes #52 --- diff --git a/registrasion/reporting/views.py b/registrasion/reporting/views.py index 395184809329e14210dc860aff93c71316f307df..02557945facabb2014aa333f0b0afe147d40d634 100644 --- a/registrasion/reporting/views.py +++ b/registrasion/reporting/views.py @@ -89,6 +89,42 @@ def items_sold(request, form): return Report("Paid items", headings, data) +@report_view("Reconcilitation") +def reconciliation(request, form): + ''' Reconciles all sales in the system with the payments in the + system. ''' + + headings = ["Thing", "Total"] + data = [] + + sales = commerce.LineItem.objects.filter( + invoice__status=commerce.Invoice.STATUS_PAID, + ).values( + "price", "quantity" + ).aggregate(total=Sum(F("price") * F("quantity"))) + + data.append(["Paid items", sales["total"]]) + + payments = commerce.PaymentBase.objects.values( + "amount", + ).aggregate(total=Sum("amount")) + + data.append(["Payments", payments["total"]]) + + ucn = commerce.CreditNote.unclaimed().values( + "amount" + ).aggregate(total=Sum("amount")) + + data.append(["Unclaimed credit notes", 0 - ucn["total"]]) + + data.append([ + "(Money not on invoices)", + sales["total"] - payments["total"] - ucn["total"], + ]) + + return Report("Sales and Payments", headings, data) + + @report_view("Product status", form_type=forms.ProductAndCategoryForm) def product_status(request, form): ''' Summarises the inventory status of the given items, grouping by diff --git a/registrasion/urls.py b/registrasion/urls.py index ba9f447c33db3a6ff81ff36f4a6ae50624a1f3b3..ae6ac8a1c397ee3e24e08f4ada3342dc56e5595f 100644 --- a/registrasion/urls.py +++ b/registrasion/urls.py @@ -42,6 +42,7 @@ reports = [ url(r"^credit_notes/?$", rv.credit_notes, name="credit_notes"), url(r"^items_sold/?$", rv.items_sold, name="items_sold"), url(r"^product_status/?$", rv.product_status, name="product_status"), + url(r"^reconciliation/?$", rv.reconciliation, name="reconciliation"), ]