1 from django.db import models
2 from django.utils.translation import ugettext_lazy as _
5 class Campaign(models.Model):
6 name = models.CharField(_('name'), max_length=255, unique=True)
7 description = models.TextField(_('description'), blank=True)
10 verbose_name = _('campaign')
11 verbose_name_plural = _('campaigns')
17 class Fundraiser(models.Model):
18 name = models.CharField(_('name'), max_length=255, unique=True)
21 verbose_name = _('fundraiser')
22 verbose_name_plural = _('fundraisers')
28 class DirectDebit(models.Model):
29 first_name = models.CharField(_('first name'), max_length=255, blank=True)
30 last_name = models.CharField(_('last name'), max_length=255, blank=True)
31 sex = models.CharField(_('sex'), max_length=1, blank=True, choices=[
35 date_of_birth = models.DateField(_('date of birth'), null=True, blank=True)
36 street = models.CharField(_('street'), max_length=255, blank=True)
37 building = models.CharField(_('building'), max_length=255, blank=True)
38 flat = models.CharField(_('flat'), max_length=255, blank=True)
39 town = models.CharField(_('town'), max_length=255, blank=True)
40 postal_code = models.CharField(_('postal code'), max_length=255, blank=True)
41 phone = models.CharField(_('phone'), max_length=255, blank=True)
42 email = models.CharField(_('e-mail'), max_length=255, blank=True)
43 iban = models.CharField(_('IBAN'), max_length=255, blank=True)
44 is_consumer = models.BooleanField(_('is a consumer'), default=True)
45 payment_id = models.CharField(_('payment identifier'), max_length=255, blank=True, unique=True)
46 agree_fundraising = models.BooleanField(_('agree fundraising'))
47 agree_newsletter = models.BooleanField(_('agree newsletter'))
49 acquisition_date = models.DateField(_('acquisition date'), help_text=_('Date from the form'))
50 submission_date = models.DateField(_('submission date'), null=True, blank=True, help_text=_('Date the fundaiser submitted the form'))
51 bank_submission_date = models.DateField(_('bank submission date'), null=True, blank=True, help_text=_('Date when the form data is submitted to the bank'))
52 bank_acceptance_date = models.DateField(_('bank accepted date'), null=True, blank=True, help_text=_('Date when bank accepted the form'))
54 fundraiser = models.ForeignKey(Fundraiser, models.PROTECT, blank=True, null=True, verbose_name=_('fundraiser'))
55 fundraiser_commission = models.IntegerField(_('fundraiser commission'), null=True, blank=True)
56 fundraiser_bill = models.CharField(_('fundaiser bill number'), max_length=255, blank=True)
58 amount = models.IntegerField(_('amount'))
60 notes = models.TextField(_('notes'), blank=True)
62 needs_redo = models.BooleanField(_('needs redo'), default=False)
63 is_cancelled = models.BooleanField(_('is cancelled'), default=False)
64 optout = models.BooleanField(_('optout'), default=False)
66 campaign = models.ForeignKey(Campaign, models.PROTECT, null=True, blank=True, verbose_name=_('campaign'))
69 verbose_name = _('direct debit')
70 verbose_name_plural = _('direct debits')
73 def get_next_payment_id(cls):
74 # Find the last object added.
75 last = cls.objects.order_by('-id').first()
78 match = re.match(r'^(.*?)(\d+)$', last.payment_id)
81 prefix = match.group(1)
82 number = int(match.group(2))
83 number_length = len(match.group(2))
86 payment_id = f'{prefix}{number:0{number_length}}'
87 if not cls.objects.filter(payment_id=payment_id).exists():