+ @property
+ def full_name(self):
+ return ' '.join((self.first_name, self.last_name)).strip()
+
+ @property
+ def street_address(self):
+ street_addr = self.street
+ if self.building:
+ street_addr += ' ' + self.building
+ if self.flat:
+ street_addr += ' m. ' + self.flat
+ street_addr = street_addr.strip()
+ return street_addr
+
+ def iban_warning(self):
+ if not self.iban:
+ return 'No IBAN'
+ if len(self.iban) != 26:
+ return 'Bad IBAN length'
+ if int(self.iban[2:] + '2521' + self.iban[:2]) % 97 != 1:
+ return 'This IBAN number looks invalid'
+ return ''
+ iban_warning.short_description = ''
+
+
+class BankExportFeedback(models.Model):
+ created_at = models.DateTimeField(auto_now_add=True)
+ csv = models.FileField(upload_to='pz/feedback/')
+
+ def save(self, **kwargs):
+ super().save(**kwargs)
+ try:
+ self.save_payment_items()
+ except AssertionError:
+ self.save_export_feedback_items()
+
+ def save_payment_items(self):
+ for payment_id, booking_date, is_dd, realised, reject_code in parse_payment_feedback(self.csv.open()):
+ debit = DirectDebit.objects.get(payment_id = payment_id)
+ b, created = self.payment_set.get_or_create(
+ debit=debit,
+ defaults={
+ 'booking_date': booking_date,
+ 'is_dd': is_dd,
+ 'realised': realised,
+ 'reject_code': reject_code,
+ }
+ )
+ if not created:
+ b.booking_date = booking_date
+ b.is_dd = is_dd
+ b.realised = realised
+ b.reject_code = reject_code
+ b.save()
+
+ def save_export_feedback_items(self):
+ for payment_id, status, comment in parse_export_feedback(self.csv.open()):
+ debit = DirectDebit.objects.get(payment_id = payment_id)
+ b, created = self.bankexportfeedbackline_set.get_or_create(
+ debit=debit,
+ defaults={
+ "status": status,
+ "comment": comment,
+ }
+ )
+ if not created:
+ b.status = status
+ b.comment = comment
+ b.save()
+ if status == 1 and not debit.bank_acceptance_date:
+ debit.bank_acceptance_date = now().date()
+ debit.save()
+
+
+class BankExportFeedbackLine(models.Model):
+ feedback = models.ForeignKey(BankExportFeedback, models.CASCADE)
+ debit = models.ForeignKey(DirectDebit, models.CASCADE)
+ status = models.SmallIntegerField()
+ comment = models.CharField(max_length=255)
+
+
+class Payment(models.Model):
+ feedback = models.ForeignKey(BankExportFeedback, models.CASCADE)
+ debit = models.ForeignKey(DirectDebit, models.CASCADE)
+ booking_date = models.DateField()
+ is_dd = models.BooleanField()
+ realised = models.BooleanField()
+ reject_code = models.CharField(max_length=128, blank=True)
+
+
+
+class BankOrder(models.Model):
+ payment_date = models.DateField(null=True, blank=True)
+ sent = models.DateTimeField(null=True, blank=True)
+ debits = models.ManyToManyField(DirectDebit, blank=True)