Improve global order filters

This commit is contained in:
Martin Gross
2020-05-06 13:12:17 +02:00
parent c0972ef39d
commit 4b01c42f31
3 changed files with 94 additions and 5 deletions

View File

@@ -1,9 +1,10 @@
from django.conf import settings
from django.db.models import Count, IntegerField, OuterRef, Q, Subquery
from django.db.models import Count, Exists, IntegerField, OuterRef, Q, Subquery
from django.utils.functional import cached_property
from django.views.generic import ListView
from pretix.base.models import Order, OrderPosition
from pretix.base.models.orders import CancellationRequest
from pretix.control.forms.filter import OrderSearchFilterForm
from pretix.control.views import LargeResultSetPaginator, PaginationMixin
@@ -29,12 +30,14 @@ class OrderSearch(PaginationMixin, ListView):
annotated = {
o['pk']: o
for o in
Order.objects.using(settings.DATABASE_REPLICA).filter(
Order.annotate_overpayments(Order.objects).using(settings.DATABASE_REPLICA).filter(
pk__in=[o.pk for o in ctx['orders']]
).annotate(
pcnt=Subquery(s, output_field=IntegerField())
pcnt=Subquery(s, output_field=IntegerField()),
has_cancellation_request=Exists(CancellationRequest.objects.filter(order=OuterRef('pk')))
).values(
'pk', 'pcnt',
'pk', 'pcnt', 'is_overpaid', 'is_underpaid', 'is_pending_with_full_payment', 'has_external_refund',
'has_pending_refund', 'has_cancellation_request'
)
}
@@ -42,6 +45,12 @@ class OrderSearch(PaginationMixin, ListView):
if o.pk not in annotated:
continue
o.pcnt = annotated.get(o.pk)['pcnt']
o.is_overpaid = annotated.get(o.pk)['is_overpaid']
o.is_underpaid = annotated.get(o.pk)['is_underpaid']
o.is_pending_with_full_payment = annotated.get(o.pk)['is_pending_with_full_payment']
o.has_external_refund = annotated.get(o.pk)['has_external_refund']
o.has_pending_refund = annotated.get(o.pk)['has_pending_refund']
o.has_cancellation_request = annotated.get(o.pk)['has_cancellation_request']
return ctx