From c8d039b1968bb91dde8324c545a64e9f601ac45a Mon Sep 17 00:00:00 2001 From: Raphael Michel Date: Fri, 12 Feb 2021 12:41:45 +0100 Subject: [PATCH] Sendmail: Allow to filter by order date --- src/pretix/plugins/sendmail/forms.py | 10 ++++++++++ .../templates/pretixplugins/sendmail/send_form.html | 2 ++ src/pretix/plugins/sendmail/views.py | 8 ++++++++ 3 files changed, 20 insertions(+) diff --git a/src/pretix/plugins/sendmail/forms.py b/src/pretix/plugins/sendmail/forms.py index b8f24e030f..28e550085f 100644 --- a/src/pretix/plugins/sendmail/forms.py +++ b/src/pretix/plugins/sendmail/forms.py @@ -65,6 +65,16 @@ class MailForm(forms.Form): label=pgettext_lazy('subevent', 'Only send to customers of dates starting before'), required=False, ) + created_from = forms.SplitDateTimeField( + widget=SplitDateTimePickerWidget(), + label=pgettext_lazy('subevent', 'Only send to customers with orders created after'), + required=False, + ) + created_to = forms.SplitDateTimeField( + widget=SplitDateTimePickerWidget(), + label=pgettext_lazy('subevent', 'Only send to customers with orders created before'), + required=False, + ) def clean(self): d = super().clean() diff --git a/src/pretix/plugins/sendmail/templates/pretixplugins/sendmail/send_form.html b/src/pretix/plugins/sendmail/templates/pretixplugins/sendmail/send_form.html index 505e71e46c..9aeae04b8f 100644 --- a/src/pretix/plugins/sendmail/templates/pretixplugins/sendmail/send_form.html +++ b/src/pretix/plugins/sendmail/templates/pretixplugins/sendmail/send_form.html @@ -15,6 +15,8 @@ {% bootstrap_field form.subevents_from layout='horizontal' %} {% bootstrap_field form.subevents_to layout='horizontal' %} {% endif %} + {% bootstrap_field form.created_from layout='horizontal' %} + {% bootstrap_field form.created_to layout='horizontal' %} {% bootstrap_field form.items layout='horizontal' %}
diff --git a/src/pretix/plugins/sendmail/views.py b/src/pretix/plugins/sendmail/views.py index 6e9ef623ce..45394ad7f5 100644 --- a/src/pretix/plugins/sendmail/views.py +++ b/src/pretix/plugins/sendmail/views.py @@ -64,6 +64,10 @@ class SenderView(EventPermissionRequiredMixin, FormView): kwargs['initial']['subevents_from'] = dateutil.parser.parse(logentry.parsed_data['subevents_from']) if logentry.parsed_data.get('subevents_to'): kwargs['initial']['subevents_to'] = dateutil.parser.parse(logentry.parsed_data['subevents_to']) + if logentry.parsed_data.get('created_from'): + kwargs['initial']['created_from'] = dateutil.parser.parse(logentry.parsed_data['created_from']) + if logentry.parsed_data.get('created_to'): + kwargs['initial']['created_to'] = dateutil.parser.parse(logentry.parsed_data['created_to']) if logentry.parsed_data.get('subevent'): try: kwargs['initial']['subevent'] = self.request.event.subevents.get( @@ -117,6 +121,10 @@ class SenderView(EventPermissionRequiredMixin, FormView): opq = opq.filter(subevent__date_from__gte=form.cleaned_data.get('subevents_from')) if form.cleaned_data.get('subevents_to'): opq = opq.filter(subevent__date_from__lt=form.cleaned_data.get('subevents_to')) + if form.cleaned_data.get('created_from'): + opq = opq.filter(order__datetime__gte=form.cleaned_data.get('created_from')) + if form.cleaned_data.get('created_to'): + opq = opq.filter(order__datetime__lt=form.cleaned_data.get('created_to')) orders = orders.annotate(match_pos=Exists(opq)).filter(match_pos=True).distinct()