PZ: add basic operations.
[wolnelektury.git] / src / pz / admin.py
index 8677931..0be845b 100644 (file)
@@ -1,5 +1,8 @@
 from django.contrib import admin
 from django.utils.translation import gettext_lazy as _
+from django.utils.timezone import now
+from fnpdjango.actions import export_as_csv_action
+from . import bank
 from . import models
 
 
@@ -8,7 +11,33 @@ admin.site.register(models.Campaign)
 
 @admin.register(models.DirectDebit)
 class DirectDebitAdmin(admin.ModelAdmin):
-    list_display = ['acquisition_date', 'amount', 'first_name', 'last_name']
+    list_display = [
+        'payment_id', 'acquisition_date',
+        'iban_valid',
+        'bank_submission_date',
+        'bank_acceptance_date',
+        'amount', 'first_name', 'last_name',
+    ]
+    date_hierarchy = 'acquisition_date'
+    search_fields = [
+        'payment_id', 'first_name', 'last_name', 'street', 'building', 'town', 'flat',
+        'phone', 'email', 'iban',
+        'notes',
+        'fundraiser_bill',
+    ]
+    list_filter = [
+        'iban_valid',
+        'agree_fundraising',
+        'agree_newsletter',
+        'fundraiser',
+        'campaign',
+        'is_cancelled',
+        'needs_redo',
+        'optout',
+        'amount',
+        'sex',
+        'is_consumer',
+    ]
     fieldsets = [
         (None, {
             "fields": [
@@ -18,7 +47,7 @@ class DirectDebitAdmin(admin.ModelAdmin):
                 ('town', 'flat'),
                 ('postal_code', 'phone'),
                 'email',
-                'iban',
+                ('iban', 'iban_valid', 'iban_warning'),
                 'payment_id',
                 'agree_contact',
                 'agree_fundraising',
@@ -40,7 +69,15 @@ class DirectDebitAdmin(admin.ModelAdmin):
             ]
         })
     ]
-    readonly_fields = ['agree_contact']
+    readonly_fields = ['agree_contact', 'iban_valid', 'iban_warning']
+
+    def set_bank_submission(m,r,q):
+        q.update(bank_submission_date=now())
+    actions = [
+        bank.bank_export,
+        set_bank_submission,
+        export_as_csv_action(),
+    ]
 
     def agree_contact(self, obj):
         return _('obligatory')