from django.contrib import admin
-from django.contrib.admin.filters import FieldListFilter
+from django.contrib.admin.filters import FieldListFilter, SimpleListFilter
from django.contrib import messages
from django.db.models import Q
from django.shortcuts import get_object_or_404, redirect
# Backport from Django 3.1.
class EmptyFieldListFilter(FieldListFilter):
+ with_empty_str = False
+
def __init__(self, field, request, params, model, model_admin, field_path):
self.lookup_kwarg = '%s__isempty' % field_path
self.lookup_val = params.get(self.lookup_kwarg)
raise IncorrectLookupParameters
lookup_condition = Q(**{'%s__isnull' % self.field_path: True})
+ if self.with_empty_str:
+ lookup_condition |= Q(**{self.field_path: ''})
if self.lookup_val == '1':
return queryset.filter(lookup_condition)
return queryset.exclude(lookup_condition)
}
+class PayedListFilter(SimpleListFilter):
+ title = 'pobrane'
+ parameter_name = 'payed'
+ def lookups(self, request, model_admin):
+ return (
+ ('yes', 'tak'),
+ ('no', 'nie'),
+ )
+
+ def queryset(self, request, queryset):
+ if self.value() == 'yes':
+ return queryset.filter(payment__is_dd=True, payment__realised=True).distinct()
+ if self.value() == 'no':
+ return queryset.exclude(payment__is_dd=True, payment__realised=True).distinct()
+
+
+
class BankExportFeedbackLineInline(admin.TabularInline):
model = models.BankExportFeedbackLine
extra = 0
+class BankPaymentInline(admin.TabularInline):
+ model = models.Payment
+ extra = 0
@admin.register(models.DirectDebit)
class DirectDebitAdmin(admin.ModelAdmin):
+ #unpaginate
+
list_display = [
'payment_id', 'acquisition_date',
'iban_valid',
+ 'latest_status',
'bank_submission_date',
'bank_acceptance_date',
'amount', 'first_name', 'last_name',
'fundraiser',
'campaign',
('cancelled_at', EmptyFieldListFilter),
+ 'latest_status',
'needs_redo',
'optout',
'amount',
'sex',
'is_consumer',
+ ('fundraiser_commission', EmptyFieldListFilter),
+ ('fundraiser_bonus', EmptyFieldListFilter),
+ PayedListFilter,
]
fieldsets = [
(None, {
('postal_code', 'phone'),
'email',
('iban', 'iban_valid', 'iban_warning'),
- 'payment_id',
+ ('payment_id', 'latest_status'),
'agree_contact',
'agree_fundraising',
'agree_newsletter',
('cancelled_at', 'needs_redo', 'optout'),
'submission_date',
'fundraiser_commission',
+ 'fundraiser_bonus',
'fundraiser_bill',
'bank_submission_date',
'bank_acceptance_date',
]
})
]
- readonly_fields = ['agree_contact', 'iban_valid', 'iban_warning']
- inlines = [BankExportFeedbackLineInline]
+ readonly_fields = ['agree_contact', 'iban_valid', 'iban_warning', 'latest_status']
+ inlines = [BankExportFeedbackLineInline, BankPaymentInline]
def set_bank_submission(m, r, q):
q.update(bank_submission_date=now())
@admin.register(models.BankExportFeedback)
class BankExportFeedbackAdmin(admin.ModelAdmin):
- inlines = [BankExportFeedbackLineInline]
+ inlines = [BankExportFeedbackLineInline, BankPaymentInline]