Don't allow changing a reg cost after it's been used
authorMagnus Hagander <magnus@hagander.net>
Thu, 29 Mar 2018 18:09:56 +0000 (20:09 +0200)
committerMagnus Hagander <magnus@hagander.net>
Thu, 29 Mar 2018 18:09:56 +0000 (20:09 +0200)
postgresqleu/confreg/backendforms.py

index 63701ac09c8d705e46414b36bac1e2c22ffc545d..88599e1dd1ee9b11e36ddc1f76aa41a51c6beb7f 100644 (file)
@@ -1,3 +1,5 @@
+from django.core.exceptions import ValidationError
+from django.db.models import Q
 import django.forms
 import django.forms.widgets
 from django.forms.widgets import TextInput
@@ -101,6 +103,12 @@ class BackendRegistrationTypeForm(BackendForm):
                        del self.fields['upsell_target']
                        self.update_protected_fields()
 
+       def clean_cost(self):
+               if self.instance and self.instance.cost != self.cleaned_data['cost']:
+                       if self.instance.conferenceregistration_set.filter(Q(payconfirmedat__isnull=False)|Q(invoice__isnull=False)|Q(bulkpayment__isnull=False)).exists():
+                               raise ValidationError("This registration type has been used, so the cost can no longer be changed")
+
+               return self.cleaned_data['cost']
 
 class BackendRegistrationDayForm(BackendForm):
        list_fields = [ 'day', ]