diff --git a/RIGS/forms.py b/RIGS/forms.py index c49f2433..95576ca3 100644 --- a/RIGS/forms.py +++ b/RIGS/forms.py @@ -144,7 +144,7 @@ class EventForm(forms.ModelForm): fields = ['is_rig', 'name', 'venue', 'start_time', 'end_date', 'start_date', 'end_time', 'meet_at', 'access_at', 'description', 'notes', 'mic', 'person', 'organisation', 'dry_hire', 'checked_in_by', 'status', - 'collector'] + 'purchase_order', 'collector'] class BaseClientEventAuthorisationForm(forms.ModelForm): @@ -171,15 +171,5 @@ class InternalClientEventAuthorisationForm(BaseClientEventAuthorisationForm): fields = ('tos', 'name', 'amount', 'uni_id', 'account_code') -class ExternalClientEventAuthorisationForm(BaseClientEventAuthorisationForm): - def __init__(self, **kwargs): - super(ExternalClientEventAuthorisationForm, self).__init__(**kwargs) - self.fields['po'].required = True - - class Meta: - model = models.EventAuthorisation - fields = ('tos', 'name', 'amount', 'po') - - class EventAuthorisationRequestForm(forms.Form): email = forms.EmailField(required=True, label='Authoriser Email') diff --git a/RIGS/migrations/0025_eventauthorisation.py b/RIGS/migrations/0025_eventauthorisation.py index 88f38ff4..2065c11d 100644 --- a/RIGS/migrations/0025_eventauthorisation.py +++ b/RIGS/migrations/0025_eventauthorisation.py @@ -19,7 +19,6 @@ class Migration(migrations.Migration): ('name', models.CharField(max_length=255)), ('uni_id', models.CharField(max_length=10, null=True, verbose_name=b'University ID', blank=True)), ('account_code', models.CharField(max_length=50, null=True, blank=True)), - ('po', models.CharField(max_length=255, null=True, verbose_name=b'purchase order', blank=True)), ('amount', models.DecimalField(verbose_name=b'authorisation amount', max_digits=10, decimal_places=2)), ('created_at', models.DateTimeField(auto_now_add=True)), ('event', models.ForeignKey(related_name='authroisations', to='RIGS.Event')), diff --git a/RIGS/migrations/0028_migrate_purchase_order.py b/RIGS/migrations/0028_migrate_purchase_order.py deleted file mode 100644 index 8a268208..00000000 --- a/RIGS/migrations/0028_migrate_purchase_order.py +++ /dev/null @@ -1,48 +0,0 @@ -# -*- coding: utf-8 -*- -from __future__ import unicode_literals - -from django.db import models, migrations -from django.db.models import F, Sum, DecimalField - - -def POs_forward(apps, schema_editor): - VatRate = apps.get_model('RIGS', 'VatRate') - Event = apps.get_model('RIGS', 'Event') - EventItem = apps.get_model('RIGS', 'EventItem') - EventAuthorisation = apps.get_model('RIGS', 'EventAuthorisation') - db_alias = schema_editor.connection.alias - for event in Event.objects.using(db_alias).filter(purchase_order__isnull=False): - sum_total = EventItem.objects.filter(event=event).aggregate( - sum_total=Sum(models.F('cost') * F('quantity'), - output_field=DecimalField( - max_digits=10, - decimal_places=2) - ) - )['sum_total'] - - vat = VatRate.objects.using(db_alias).filter(start_at__lte=event.start_date).latest() - total = sum_total + sum_total * vat.rate - - EventAuthorisation.objects.using(db_alias).create(event=event, name='LEGACY', - email='treasurer@nottinghamtec.co.uk', - amount=total, - po=event.purchase_order) - - -def POs_reverse(apps, schema_editor): - EventAuthorisation = apps.get_model('RIGS', 'EventAuthorisation') - db_alias = schema_editor.connection.alias - for auth in EventAuthorisation.objects.using(db_alias).filter(po__isnull=False): - auth.event.purchase_order = auth.po - auth.delete() - - -class Migration(migrations.Migration): - dependencies = [ - ('RIGS', '0027_eventauthorisation_event_singular'), - ] - - operations = [ - migrations.RunPython(POs_forward, POs_reverse), - migrations.RemoveField(model_name='event', name='purchase_order') - ] diff --git a/RIGS/migrations/0029_eventauthorisation_sent_by.py b/RIGS/migrations/0029_eventauthorisation_sent_by.py index 80c86299..592bc968 100644 --- a/RIGS/migrations/0029_eventauthorisation_sent_by.py +++ b/RIGS/migrations/0029_eventauthorisation_sent_by.py @@ -8,7 +8,7 @@ from django.conf import settings class Migration(migrations.Migration): dependencies = [ - ('RIGS', '0028_migrate_purchase_order'), + ('RIGS', '0027_eventauthorisation_event_singular'), ] operations = [ diff --git a/RIGS/models.py b/RIGS/models.py index ebb31ca6..c1a33eb8 100644 --- a/RIGS/models.py +++ b/RIGS/models.py @@ -329,6 +329,7 @@ class Event(models.Model, RevisionMixin): # Monies payment_method = models.CharField(max_length=255, blank=True, null=True) payment_received = models.CharField(max_length=255, blank=True, null=True) + purchase_order = models.CharField(max_length=255, blank=True, null=True, verbose_name='PO') collector = models.CharField(max_length=255, blank=True, null=True, verbose_name='collected by') # Authorisation request details @@ -388,7 +389,7 @@ class Event(models.Model, RevisionMixin): @property def authorised(self): - return self.authorisation.amount == self.total + return not self.internal and self.purchase_order or self.authorisation.amount == self.total @property def has_start_time(self): @@ -450,6 +451,10 @@ class Event(models.Model, RevisionMixin): else: return endDate + @property + def internal(self): + return self.organisation and self.organisation.union_account + objects = EventManager() def get_absolute_url(self): @@ -513,7 +518,6 @@ class EventAuthorisation(models.Model, RevisionMixin): name = models.CharField(max_length=255) uni_id = models.CharField(max_length=10, blank=True, null=True, verbose_name="University ID") account_code = models.CharField(max_length=50, blank=True, null=True) - po = models.CharField(max_length=255, blank=True, null=True, verbose_name="purchase order") amount = models.DecimalField(max_digits=10, decimal_places=2, verbose_name="authorisation amount") sent_by = models.ForeignKey('RIGS.Profile') diff --git a/RIGS/rigboard.py b/RIGS/rigboard.py index e4c124c2..4546b502 100644 --- a/RIGS/rigboard.py +++ b/RIGS/rigboard.py @@ -137,6 +137,7 @@ class EventDuplicate(EventUpdate): old = super(EventDuplicate, self).get_object(queryset) # Get the object (the event you're duplicating) new = copy.copy(old) # Make a copy of the object in memory new.based_on = old # Make the new event based on the old event + new.purchase_order = None # Remove all the authorisation information from the new event new.auth_request_to = None @@ -256,20 +257,12 @@ class EventAuthorise(generic.UpdateView): return getattr(self.event, 'authorisation', None) def get_form_class(self): - if self.event.organisation is not None and self.event.organisation.union_account: - return forms.InternalClientEventAuthorisationForm - else: - return forms.ExternalClientEventAuthorisationForm + return forms.InternalClientEventAuthorisationForm def get_context_data(self, **kwargs): context = super(EventAuthorise, self).get_context_data(**kwargs) context['event'] = self.event - if self.get_form_class() is forms.InternalClientEventAuthorisationForm: - context['internal'] = True - else: - context['internal'] = False - context['tos_url'] = settings.TERMS_OF_HIRE_URL return context @@ -304,6 +297,7 @@ class EventAuthorise(generic.UpdateView): "This URL is invalid. Please ask your TEC contact for a new URL") return super(EventAuthorise, self).dispatch(request, *args, **kwargs) + class EventAuthorisationRequest(generic.FormView, generic.detail.SingleObjectMixin): model = models.Event form_class = forms.EventAuthorisationRequestForm diff --git a/RIGS/templates/RIGS/event_detail.html b/RIGS/templates/RIGS/event_detail.html index 051aec4f..5f2885b5 100644 --- a/RIGS/templates/RIGS/event_detail.html +++ b/RIGS/templates/RIGS/event_detail.html @@ -71,7 +71,7 @@ {% endif %} - {% if event.is_rig %} + {% if event.is_rig and event.internal %}
- I agree that I am authorised to approve this event. I agree that I am the - President/Treasurer or account holder of the hirer, or that I - have the written permission of the - President/Treasurer or account holder of the hirer stating that - I can authorise this event. -
-+ I agree that I am authorised to approve this event. I agree that I am the + President/Treasurer or account holder of the hirer, or that I + have the written permission of the + President/Treasurer or account holder of the hirer stating that + I can authorise this event. +
+