From c6b7bbc219da9fab3600e20bbdce921c5d16e4f6 Mon Sep 17 00:00:00 2001 From: Tom Price Date: Tue, 23 May 2017 18:19:02 +0100 Subject: [PATCH] Change to just using online auth for internal clients. This effectively reverts 067e03b. --- RIGS/forms.py | 12 +--- RIGS/migrations/0025_eventauthorisation.py | 1 - .../migrations/0028_migrate_purchase_order.py | 48 ------------- .../0029_eventauthorisation_sent_by.py | 2 +- RIGS/models.py | 8 ++- RIGS/rigboard.py | 12 +--- RIGS/templates/RIGS/event_detail.html | 24 ++++--- RIGS/templates/RIGS/event_detail_buttons.html | 49 +++++++------ RIGS/templates/RIGS/event_form.html | 9 +++ RIGS/templates/RIGS/event_invoice.html | 20 +++--- RIGS/templates/RIGS/event_print_page.xml | 20 +++--- .../RIGS/eventauthorisation_form.html | 71 ++++++++----------- .../RIGS/eventauthorisation_success.html | 9 +-- RIGS/templates/RIGS/invoice_detail.html | 4 +- RIGS/templates/RIGS/invoice_list.html | 4 +- RIGS/test_functional.py | 13 +++- 16 files changed, 123 insertions(+), 183 deletions(-) delete mode 100644 RIGS/migrations/0028_migrate_purchase_order.py 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 %}
Client Authorisation
@@ -183,17 +183,23 @@ {% if event.is_rig %}
 
-
Authorisation Request
-
{{ object.auth_request_to|yesno:"Yes,No" }}
+ {% if object.internal %} +
Authorisation Request
+
{{ object.auth_request_to|yesno:"Yes,No" }}
-
By
-
{{ object.auth_request_by }}
+
By
+
{{ object.auth_request_by }}
-
At
-
{{ object.auth_request_at|date:"D d M Y H:i"|default:"" }}
+
At
+
{{ object.auth_request_at|date:"D d M Y H:i"|default:"" }}
-
To
-
{{ object.auth_request_to }}
+
To
+
{{ object.auth_request_to }}
+ + {% else %} +
PO
+
{{ object.purchase_order }}
+ {% endif %} {% endif %}
diff --git a/RIGS/templates/RIGS/event_detail_buttons.html b/RIGS/templates/RIGS/event_detail_buttons.html index 9ad4b189..878684cc 100644 --- a/RIGS/templates/RIGS/event_detail_buttons.html +++ b/RIGS/templates/RIGS/event_detail_buttons.html @@ -11,29 +11,32 @@ class="glyphicon glyphicon-duplicate"> {% if event.is_rig %} - - - - + {% if event.internal %} + + + + + {% endif %} + {% if perms.RIGS.add_invoice %}
+ +
+ + +
+ {% render_field form.purchase_order class+="form-control" %} +
+
diff --git a/RIGS/templates/RIGS/event_invoice.html b/RIGS/templates/RIGS/event_invoice.html index 71136b35..ec9755c0 100644 --- a/RIGS/templates/RIGS/event_invoice.html +++ b/RIGS/templates/RIGS/event_invoice.html @@ -61,21 +61,14 @@ {% endif %} - {% if object.organisation %} - {{ object.organisation.name }} -
- {{ object.organisation.union_account|yesno:'Internal,External' }} - {% else %} - {{ object.person.name }} -
- External - {% endif %} - + {{ object.organisation.name }} +
+ {{ object.internal|yesno:'Internal,External' }} {{ object.sum_total|floatformat:2 }}
- {{ object.authorisation.po }} + {% if not object.internal %}{{ object.purchase_order }}{% endif %} {% if object.mic %} @@ -86,7 +79,10 @@ {% endif %} -
+ diff --git a/RIGS/templates/RIGS/event_print_page.xml b/RIGS/templates/RIGS/event_print_page.xml index 27317c57..73510b68 100644 --- a/RIGS/templates/RIGS/event_print_page.xml +++ b/RIGS/templates/RIGS/event_print_page.xml @@ -249,13 +249,12 @@ - {% if object.authorised %} - - Event authorised online by {{ object.authorisation.name }} ({{ object.authorisation.email }}) at - {{ object.authorisation.last_edited_at }}. - + {% if object.internal and object.authorised %} + + Event authorised online by {{ object.authorisation.name }} ({{ object.authorisation.email }}) at + {{ object.authorisation.last_edited_at }}. + - {% if object.organisation.union_account %} University ID @@ -268,19 +267,18 @@ £ {{ object.authorisation.amount|floatformat:2 }} - {% else %} + {% elif not object.internal and object.purchase_order %} + Purchase Order - Authorised Amount - {{ object.authorisation.po }} - £ {{ object.authorisation.amount|floatformat:2 }} + + {{ object.purchase_order }} {% endif %} - {% endif %} diff --git a/RIGS/templates/RIGS/eventauthorisation_form.html b/RIGS/templates/RIGS/eventauthorisation_form.html index 9182df41..06df386d 100644 --- a/RIGS/templates/RIGS/eventauthorisation_form.html +++ b/RIGS/templates/RIGS/eventauthorisation_form.html @@ -9,11 +9,11 @@ $('[data-toggle="tooltip"]').tooltip(); }); - $('form').on('submit', function() { - $('#loading-modal').modal({ - backdrop: 'static', - show: true - }); + $('form').on('submit', function () { + $('#loading-modal').modal({ + backdrop: 'static', + show: true + }); }); {% endblock %} @@ -54,17 +54,15 @@ {% csrf_token %} {% include 'form_errors.html' %}
- {% if 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. -

-
- {% endif %} +
+

+ 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. +

+
- {% if internal %} -
- -
- {% render_field form.uni_id class+="form-control" %} -
+
+ +
+ {% render_field form.uni_id class+="form-control" %}
- {% endif %} +
- {% if internal %} -
- -
- {% render_field form.account_code class+="form-control" %} -
+
+ +
+ {% render_field form.account_code class+="form-control" %}
- {% else %} -
- -
- {% render_field form.po class+="form-control" %} -
-
- {% endif %} +
diff --git a/RIGS/templates/RIGS/eventauthorisation_success.html b/RIGS/templates/RIGS/eventauthorisation_success.html index 2b899076..cb24738a 100644 --- a/RIGS/templates/RIGS/eventauthorisation_success.html +++ b/RIGS/templates/RIGS/eventauthorisation_success.html @@ -49,13 +49,8 @@
- {% if internal %} -
Account code
-
{{ object.account_code }}
- {% else %} -
PO
-
{{ object.po }}
- {% endif %} +
Account code
+
{{ object.account_code }}
Authorised amount
£ {{ object.amount|floatformat:2 }}
diff --git a/RIGS/templates/RIGS/invoice_detail.html b/RIGS/templates/RIGS/invoice_detail.html index a55927f8..b305a04f 100644 --- a/RIGS/templates/RIGS/invoice_detail.html +++ b/RIGS/templates/RIGS/invoice_detail.html @@ -89,7 +89,7 @@ {% endif %} - {% if object.event.organisation.union_account %} + {% if object.event.internal %} {# internal #}
Uni ID
{{ object.event.authorisation.uni_id }}
@@ -98,7 +98,7 @@
{{ object.event.authorisation.account_code }}
{% else %}
PO
-
{{ object.event.authorisation.po }}
+
{{ object.event.purchase_order }}
{% endif %}
Authorised at
diff --git a/RIGS/templates/RIGS/invoice_list.html b/RIGS/templates/RIGS/invoice_list.html index 62012238..63e61e11 100644 --- a/RIGS/templates/RIGS/invoice_list.html +++ b/RIGS/templates/RIGS/invoice_list.html @@ -50,7 +50,7 @@ {% if object.event.organisation %} {{ object.event.organisation.name }}
- {{ object.event.organisation.union_account|yesno:'Internal,External' }} + {{ object.event.internal|yesno:'Internal,External' }} {% else %} {{ object.event.person.name }}
@@ -62,7 +62,7 @@ {{ object.balance|floatformat:2 }}
- {{ object.event.authorisation.po }} + {{ object.event.purchase_order }} diff --git a/RIGS/test_functional.py b/RIGS/test_functional.py index 4cd23526..27675442 100644 --- a/RIGS/test_functional.py +++ b/RIGS/test_functional.py @@ -496,6 +496,7 @@ class EventTest(LiveServerTestCase): testEvent = models.Event.objects.create(name="TE E1", status=models.Event.PROVISIONAL, start_date=date.today() + timedelta(days=6), description="start future no end", + purchase_order='TESTPO', auth_request_by=self.profile, auth_request_at=self.create_datetime(2015, 06, 04, 10, 00), auth_request_to="some@email.address") @@ -570,6 +571,10 @@ class EventTest(LiveServerTestCase): self.assertIn("Test Item 3", table.text) infoPanel = self.browser.find_element_by_xpath('//div[contains(text(), "Event Info")]/..') + self.assertIn("N0000%d" % testEvent.pk, + infoPanel.find_element_by_xpath('//dt[text()="Based On"]/following-sibling::dd[1]').text) + # Check the PO hasn't carried through + self.assertNotIn("TESTPO", infoPanel.find_element_by_xpath('//dt[text()="PO"]/following-sibling::dd[1]').text) self.assertIn("N%05d"%testEvent.pk, infoPanel.find_element_by_xpath('//dt[text()="Based On"]/following-sibling::dd[1]').text) @@ -578,6 +583,10 @@ class EventTest(LiveServerTestCase): #Check that based-on hasn't crept into the old event infoPanel = self.browser.find_element_by_xpath('//div[contains(text(), "Event Info")]/..') + self.assertNotIn("N0000%d" % testEvent.pk, + infoPanel.find_element_by_xpath('//dt[text()="Based On"]/following-sibling::dd[1]').text) + # Check the PO remains on the old event + self.assertIn("TESTPO", infoPanel.find_element_by_xpath('//dt[text()="PO"]/following-sibling::dd[1]').text) self.assertNotIn("N%05d"%testEvent.pk, infoPanel.find_element_by_xpath('//dt[text()="Based On"]/following-sibling::dd[1]').text) @@ -1108,7 +1117,7 @@ class ClientEventAuthorisationTest(TestCase): self.assertContains(response, "Terms of Hire") response = self.client.post(self.url) - self.assertContains(response, "This field is required.", 4) + self.assertContains(response, "This field is required.", 5) data = self.auth_data data['amount'] = self.event.total + 1 @@ -1142,7 +1151,7 @@ class ClientEventAuthorisationTest(TestCase): def test_duplicate_warning(self): auth = models.EventAuthorisation.objects.create(event=self.event, name='Test ABC', email='dupe@functional.test', - po='ABC12345', amount=self.event.total, sent_by=self.profile) + amount=self.event.total, sent_by=self.profile) response = self.client.get(self.url) self.assertContains(response, 'This event has already been authorised.')