mirror of
https://github.com/pretix/pretix.git
synced 2026-05-08 15:44:02 +00:00
Improve global order filters
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user