diff --git a/registrasion/reporting/views.py b/registrasion/reporting/views.py index 39518480..02557945 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 ba9f447c..ae6ac8a1 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"), ]