diff --git a/registrasion/forms.py b/registrasion/forms.py index 4839b733..150219f1 100644 --- a/registrasion/forms.py +++ b/registrasion/forms.py @@ -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 diff --git a/registrasion/urls.py b/registrasion/urls.py index 0d21854c..2028d86b 100644 --- a/registrasion/urls.py +++ b/registrasion/urls.py @@ -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"), diff --git a/registrasion/views.py b/registrasion/views.py index 8b0d2b5d..0e62a649 100644 --- a/registrasion/views.py +++ b/registrasion/views.py @@ -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