PZ admin changes
authorRadek Czajka <rczajka@rczajka.pl>
Thu, 27 Jan 2022 13:06:11 +0000 (14:06 +0100)
committerRadek Czajka <rczajka@rczajka.pl>
Thu, 27 Jan 2022 13:06:11 +0000 (14:06 +0100)
src/pz/admin.py
src/pz/migrations/0010_auto_20220127_1359.py [new file with mode: 0644]
src/pz/models.py

index 9687948..1373a56 100644 (file)
@@ -60,6 +60,7 @@ class DirectDebitAdmin(admin.ModelAdmin):
     list_display = [
         'payment_id', 'acquisition_date',
         'iban_valid',
     list_display = [
         'payment_id', 'acquisition_date',
         'iban_valid',
+        'latest_status',
         'bank_submission_date',
         'bank_acceptance_date',
         'amount', 'first_name', 'last_name',
         'bank_submission_date',
         'bank_acceptance_date',
         'amount', 'first_name', 'last_name',
@@ -78,11 +79,14 @@ class DirectDebitAdmin(admin.ModelAdmin):
         'fundraiser',
         'campaign',
         ('cancelled_at', EmptyFieldListFilter),
         'fundraiser',
         'campaign',
         ('cancelled_at', EmptyFieldListFilter),
+        'latest_status',
         'needs_redo',
         'optout',
         'amount',
         'sex',
         'is_consumer',
         'needs_redo',
         'optout',
         'amount',
         'sex',
         'is_consumer',
+        ('fundraiser_commission', EmptyFieldListFilter),
+        ('fundraiser_bonus', EmptyFieldListFilter),
     ]
     fieldsets = [
         (None, {
     ]
     fieldsets = [
         (None, {
@@ -94,7 +98,7 @@ class DirectDebitAdmin(admin.ModelAdmin):
                 ('postal_code', 'phone'),
                 'email',
                 ('iban', 'iban_valid', 'iban_warning'),
                 ('postal_code', 'phone'),
                 'email',
                 ('iban', 'iban_valid', 'iban_warning'),
-                'payment_id',
+                ('payment_id', 'latest_status'),
                 'agree_contact',
                 'agree_fundraising',
                 'agree_newsletter',
                 'agree_contact',
                 'agree_fundraising',
                 'agree_newsletter',
@@ -108,6 +112,7 @@ class DirectDebitAdmin(admin.ModelAdmin):
             ('cancelled_at', 'needs_redo', 'optout'),
             'submission_date',
             'fundraiser_commission',
             ('cancelled_at', 'needs_redo', 'optout'),
             'submission_date',
             'fundraiser_commission',
+            'fundraiser_bonus',
             'fundraiser_bill',
             'bank_submission_date',
             'bank_acceptance_date',
             'fundraiser_bill',
             'bank_submission_date',
             'bank_acceptance_date',
@@ -115,7 +120,7 @@ class DirectDebitAdmin(admin.ModelAdmin):
             ]
         })
     ]
             ]
         })
     ]
-    readonly_fields = ['agree_contact', 'iban_valid', 'iban_warning']
+    readonly_fields = ['agree_contact', 'iban_valid', 'iban_warning', 'latest_status']
     inlines = [BankExportFeedbackLineInline]
 
     def set_bank_submission(m, r, q):
     inlines = [BankExportFeedbackLineInline]
 
     def set_bank_submission(m, r, q):
diff --git a/src/pz/migrations/0010_auto_20220127_1359.py b/src/pz/migrations/0010_auto_20220127_1359.py
new file mode 100644 (file)
index 0000000..c0310b7
--- /dev/null
@@ -0,0 +1,23 @@
+# Generated by Django 2.2.25 on 2022-01-27 12:59
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('pz', '0009_remove_directdebit_is_cancelled'),
+    ]
+
+    operations = [
+        migrations.AddField(
+            model_name='directdebit',
+            name='fundraiser_bonus',
+            field=models.IntegerField(blank=True, null=True, verbose_name='fundraiser bonus'),
+        ),
+        migrations.AddField(
+            model_name='directdebit',
+            name='latest_status',
+            field=models.CharField(blank=True, max_length=255),
+        ),
+    ]
index 45e6c62..87e25fc 100644 (file)
@@ -57,6 +57,7 @@ class DirectDebit(models.Model):
 
     fundraiser = models.ForeignKey(Fundraiser, models.PROTECT, blank=True, null=True, verbose_name=_('fundraiser'))
     fundraiser_commission = models.IntegerField(_('fundraiser commission'), null=True, blank=True)
 
     fundraiser = models.ForeignKey(Fundraiser, models.PROTECT, blank=True, null=True, verbose_name=_('fundraiser'))
     fundraiser_commission = models.IntegerField(_('fundraiser commission'), null=True, blank=True)
+    fundraiser_bonus = models.IntegerField(_('fundraiser bonus'), null=True, blank=True)
     fundraiser_bill = models.CharField(_('fundaiser bill number'), max_length=255, blank=True)
 
     amount = models.IntegerField(_('amount'), null=True, blank=True)
     fundraiser_bill = models.CharField(_('fundaiser bill number'), max_length=255, blank=True)
 
     amount = models.IntegerField(_('amount'), null=True, blank=True)
@@ -69,15 +70,23 @@ class DirectDebit(models.Model):
 
     campaign = models.ForeignKey(Campaign, models.PROTECT, null=True, blank=True, verbose_name=_('campaign'))
 
 
     campaign = models.ForeignKey(Campaign, models.PROTECT, null=True, blank=True, verbose_name=_('campaign'))
 
+    latest_status = models.CharField(max_length=255, blank=True)
+    
     class Meta:
         verbose_name = _('direct debit')
         verbose_name_plural = _('direct debits')
 
     def __str__(self):
     class Meta:
         verbose_name = _('direct debit')
         verbose_name_plural = _('direct debits')
 
     def __str__(self):
-        return self.payment_id
+        return "{} {}".format(self.payment_id, self.latest_status)
+
+    def get_latest_status(self):
+        line = self.bankexportfeedbackline_set.order_by('-feedback__created_at').first()
+        if line is None: return ""
+        return line.comment
 
     def save(self, **kwargs):
         self.iban_valid = not self.iban_warning() if self.iban else None
 
     def save(self, **kwargs):
         self.iban_valid = not self.iban_warning() if self.iban else None
+        self.latest_status = self.get_latest_status()
         super().save(**kwargs)
 
     @classmethod
         super().save(**kwargs)
 
     @classmethod