Adds paid invoices by date report
This commit is contained in:
parent
851c37508a
commit
f41bd9c65b
2 changed files with 47 additions and 1 deletions
|
@ -1,10 +1,13 @@
|
|||
import forms
|
||||
|
||||
import collections
|
||||
import datetime
|
||||
|
||||
from django.contrib.auth.decorators import user_passes_test
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.db import models
|
||||
from django.db.models import F, Q
|
||||
from django.db.models import Count, Sum
|
||||
from django.db.models import Count, Max, Sum
|
||||
from django.db.models import Case, When, Value
|
||||
from django.shortcuts import render
|
||||
|
||||
|
@ -265,6 +268,44 @@ def product_status(request, form):
|
|||
return ListReport("Inventory", headings, data)
|
||||
|
||||
|
||||
@report_view("Paid invoices by date", form_type=forms.ProductAndCategoryForm)
|
||||
def paid_invoices_by_date(request, form):
|
||||
''' Shows the number of paid invoices containing given products or
|
||||
categories per day. '''
|
||||
|
||||
products = form.cleaned_data["product"]
|
||||
categories = form.cleaned_data["category"]
|
||||
|
||||
invoices = commerce.Invoice.objects.filter(
|
||||
Q(lineitem__product__in=products) | Q(lineitem__product__category__in=categories),
|
||||
status=commerce.Invoice.STATUS_PAID,
|
||||
)
|
||||
|
||||
payments = commerce.PaymentBase.objects.all()
|
||||
payments = payments.filter(
|
||||
invoice__in=invoices,
|
||||
)
|
||||
payments = payments.order_by("invoice")
|
||||
invoice_max_time = payments.values("invoice").annotate(max_time=Max("time"))
|
||||
|
||||
by_date = collections.defaultdict(int)
|
||||
|
||||
for line in invoice_max_time:
|
||||
time = line["max_time"]
|
||||
date = datetime.datetime(
|
||||
year=time.year, month=time.month, day=time.day
|
||||
)
|
||||
by_date[date] += 1
|
||||
|
||||
data = [(date, count) for date, count in sorted(by_date.items())]
|
||||
data = [(date.strftime("%Y-%m-%d"), count) for date, count in data]
|
||||
|
||||
return ListReport(
|
||||
"Paid Invoices By Date",
|
||||
["date", "count"],
|
||||
data,
|
||||
)
|
||||
|
||||
@report_view("Credit notes")
|
||||
def credit_notes(request, form):
|
||||
''' Shows all of the credit notes in the system. '''
|
||||
|
|
|
@ -46,6 +46,11 @@ reports = [
|
|||
url(r"^attendee/([0-9]*)$", rv.attendee, name="attendee"),
|
||||
url(r"^credit_notes/?$", rv.credit_notes, name="credit_notes"),
|
||||
url(r"^items_sold/?$", rv.items_sold, name="items_sold"),
|
||||
url(
|
||||
r"^paid_invoices_by_date/?$",
|
||||
rv.paid_invoices_by_date,
|
||||
name="paid_invoices_by_date"
|
||||
),
|
||||
url(r"^product_status/?$", rv.product_status, name="product_status"),
|
||||
url(r"^reconciliation/?$", rv.reconciliation, name="reconciliation"),
|
||||
]
|
||||
|
|
Loading…
Reference in a new issue