From a88fed283a38deeea38328b3a308c6e9b0eb76aa Mon Sep 17 00:00:00 2001 From: Raphael Michel Date: Tue, 22 Jun 2021 16:30:26 +0200 Subject: [PATCH] Customers: Additional filter form fields --- src/pretix/control/forms/filter.py | 44 ++++++++++++++++--- .../pretixcontrol/organizers/customer.html | 33 +++++++------- .../pretixcontrol/organizers/customers.html | 2 +- 3 files changed, 57 insertions(+), 22 deletions(-) diff --git a/src/pretix/control/forms/filter.py b/src/pretix/control/forms/filter.py index cc3a9b4ce..c94ccf19a 100644 --- a/src/pretix/control/forms/filter.py +++ b/src/pretix/control/forms/filter.py @@ -1049,6 +1049,26 @@ class CustomerFilterForm(FilterForm): }), required=False ) + status = forms.ChoiceField( + label=_('Status'), + required=False, + choices=( + ('', _('All')), + ('active', _('active')), + ('disabled', _('disabled')), + ('unverified', _('not yet activated')), + ) + ) + memberships = forms.ChoiceField( + label=_('Memberships'), + required=False, + choices=( + ('', _('All')), + ('no', _('Has no memberships')), + ('any', _('Has any membership')), + ('valid', _('Has valid membership')), + ) + ) def __init__(self, *args, **kwargs): kwargs.pop('request') @@ -1065,12 +1085,26 @@ class CustomerFilterForm(FilterForm): | Q(identifier__istartswith=query) ) - if fdata.get('ordering'): - qs = qs.order_by(self.get_order_by()) - else: - qs = qs.order_by('-email') + if fdata.get('status') == 'active': + qs = qs.filter(is_active=True, is_verified=True) + elif fdata.get('status') == 'disabled': + qs = qs.filter(is_active=False) + elif fdata.get('status') == 'unverified': + qs = qs.filter(is_verified=False) - return qs + if fdata.get('memberships') == 'no': + qs = qs.filter(memberships__isnull=True) + elif fdata.get('memberships') == 'any': + qs = qs.filter(memberships__isnull=False) + elif fdata.get('memberships') == 'valid': + qs = qs.filter(memberships__date_start__lt=now(), memberships__date_end__gt=now(), memberships__canceled=False) + + if fdata.get('ordering'): + qs = qs.order_by(self.get_order_by()) + else: + qs = qs.order_by('-email') + + return qs.distinct() class TeamFilterForm(FilterForm): diff --git a/src/pretix/control/templates/pretixcontrol/organizers/customer.html b/src/pretix/control/templates/pretixcontrol/organizers/customer.html index b37b44943..34278fd6e 100644 --- a/src/pretix/control/templates/pretixcontrol/organizers/customer.html +++ b/src/pretix/control/templates/pretixcontrol/organizers/customer.html @@ -91,7 +91,8 @@ {% for m in memberships %} - {% if m.canceled %}{% endif %} + {% if m.canceled %} + {% endif %} {{ m.membership_type.name }} {% if m.canceled %}{% endif %} {% if m.testmode %}{% trans "TEST MODE" %}{% endif %} @@ -143,17 +144,17 @@ {% endfor %} - - - - - - {% trans "Add membership" %} - - - - + + + + + + {% trans "Add membership" %} + + + +
@@ -191,7 +192,7 @@ + data-toggle="tooltip" title="{% trans o.sales_channel_obj.verbose_name %}"> {{ o.datetime|date:"SHORT_DATETIME_FORMAT" }} {% if o.customer_id != customer.pk %} {% trans "REFUND PENDING" %} - {% elif o.has_pending_refund %} + {% elif o.has_pending_refund %} {% trans "REFUND PENDING" %} {% endif %} {% if o.is_overpaid %} {% trans "OVERPAID" %} - {% elif o.is_underpaid %} + {% elif o.is_underpaid %} {% trans "UNDERPAID" %} - {% elif o.is_pending_with_full_payment %} + {% elif o.is_pending_with_full_payment %} {% trans "FULLY PAID" %} {% endif %} {% if o.computed_payment_refund_sum == o.total or o.computed_payment_refund_sum == 0 %} diff --git a/src/pretix/control/templates/pretixcontrol/organizers/customers.html b/src/pretix/control/templates/pretixcontrol/organizers/customers.html index 7eebdaa2f..3ebe36a6c 100644 --- a/src/pretix/control/templates/pretixcontrol/organizers/customers.html +++ b/src/pretix/control/templates/pretixcontrol/organizers/customers.html @@ -25,7 +25,7 @@ {% bootstrap_field filter_form.status layout='inline' %}
- {% bootstrap_field filter_form.membership layout='inline' %} + {% bootstrap_field filter_form.memberships layout='inline' %}