Adds forms for nag_unpaid

This commit is contained in:
Christopher Neugebauer 2016-12-07 11:19:30 +11:00
parent 37fbc2ee40
commit fcf4e5cffb
3 changed files with 46 additions and 0 deletions

View file

@ -4,6 +4,7 @@ from registrasion.models import inventory
from django import forms
from django.core.exceptions import ValidationError
from django.db.models import Q
class ApplyCreditNoteForm(forms.Form):
@ -394,3 +395,30 @@ def staff_products_formset_factory(user):
''' Creates a formset of StaffProductsForm for the given user. '''
form_type = staff_products_form_factory(user)
return forms.formset_factory(form_type)
class InvoiceNagForm(forms.Form):
invoice = forms.ModelMultipleChoiceField(
widget=forms.CheckboxSelectMultiple,
queryset=commerce.Invoice.objects.all(),
)
def __init__(self, *a, **k):
category = k.pop('category', None) or []
product = k.pop('product', None) or []
category = [int(i) for i in category]
product = [int(i) for i in product]
super(InvoiceNagForm, self).__init__(*a, **k)
print repr(category), repr(product)
qs = commerce.Invoice.objects.filter(
status=commerce.Invoice.STATUS_UNPAID,
).filter(
Q(lineitem__product__category__in=category) |
Q(lineitem__product__in=product)
)
self.fields['invoice'].queryset = qs

View file

@ -13,6 +13,7 @@ from .views import (
invoice,
invoice_access,
manual_payment,
nag_unpaid,
product_category,
refund,
review,
@ -34,6 +35,7 @@ public = [
refund, name="refund"),
url(r"^invoice_access/([A-Z0-9]+)$", invoice_access,
name="invoice_access"),
url(r"^nag_unpaid$", nag_unpaid, name="nag_unpaid"),
url(r"^profile$", edit_profile, name="attendee_edit"),
url(r"^register$", guided_registration, name="guided_registration"),
url(r"^review$", review, name="review"),

View file

@ -916,3 +916,19 @@ def extend_reservation(request, user_id, days=7):
cart.extend_reservation(datetime.timedelta(days=days))
return redirect(request.META["HTTP_REFERER"])
@user_passes_test(_staff_only)
def nag_unpaid(request):
''' Allows staff to nag users with unpaid invoices. '''
category = request.GET.getlist("category", [])
product = request.GET.getlist("product", [])
form = forms.InvoiceNagForm(
request.POST or None,
category=category,
product=product,
)
print form.fields['invoice'].queryset