@@ -80,24 +80,60 @@ def items_sold(request, form):
line["description"], line["total_quantity"],
line["price"], cost,
])
total_income += cost
data.append([
"(TOTAL)", "--", "--", total_income,
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"
data.append(["Unclaimed credit notes", 0 - ucn["total"]])
"(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
invoice status. '''
products = form.cleaned_data["product"]
categories = form.cleaned_data["category"]
items = commerce.ProductItem.objects.filter(
Q(product__in=products) | Q(product__category__in=categories),
).select_related("cart", "product")
@@ -262,45 +298,64 @@ def attendee(request, form, attendee_id=None):
credit_notes = commerce.CreditNote.objects.filter(
invoice__user=attendee.user,
)
for credit_note in credit_notes:
credit_note.id, credit_note.status, credit_note.value,
reports.append(
Report("Credit Notes", headings, data, link_view="credit_note")
# All payments
headings = ["To Invoice", "Payment ID", "Reference", "Amount"]
payments = commerce.PaymentBase.objects.filter(
for payment in payments:
payment.invoice.id, payment.id, payment.reference, payment.amount,
Report("Payments", headings, data, link_view="invoice")
return reports
def attendee_list(request):
''' Returns a list of all attendees. '''
attendees = people.Attendee.objects.all().select_related(
"attendeeprofilebase",
"user",
attendees = attendees.values("id", "user__email").annotate(
attendees = attendees.annotate(
has_registered=Count(
Q(user__invoice__status=commerce.Invoice.STATUS_PAID)
),
headings = [
"User ID", "Email", "Has registered",
"User ID", "Name", "Email", "Has registered",
]
for attendee in attendees:
attendee["id"],
attendee["user__email"],
attendee["has_registered"],
attendee.id,
attendee.attendeeprofilebase.attendee_name(),
attendee.user.email,
attendee.has_registered > 0,
# Sort by whether they've registered, then ID.
data.sort(key=lambda attendee: (-attendee[2], attendee[0]))
data.sort(key=lambda attendee: (-attendee[3], attendee[0]))
return Report("Attendees", headings, data, link_view="attendee")