Remove Event.purchase_order in favour of a simple EventAuthorisation object.

This commit is contained in:
Tom Price
2017-04-10 23:14:09 +01:00
parent 391d9ef28f
commit 067e03b757
8 changed files with 49 additions and 26 deletions

View File

@@ -140,7 +140,7 @@ class EventForm(forms.ModelForm):
fields = ['is_rig', 'name', 'venue', 'start_time', 'end_date', 'start_date', fields = ['is_rig', 'name', 'venue', 'start_time', 'end_date', 'start_date',
'end_time', 'meet_at', 'access_at', 'description', 'notes', 'mic', 'end_time', 'meet_at', 'access_at', 'description', 'notes', 'mic',
'person', 'organisation', 'dry_hire', 'checked_in_by', 'status', 'person', 'organisation', 'dry_hire', 'checked_in_by', 'status',
'collector', 'purchase_order'] 'collector']
class BaseClientEventAuthorisationForm(forms.ModelForm): class BaseClientEventAuthorisationForm(forms.ModelForm):

View File

@@ -0,0 +1,47 @@
# -*- 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)
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')
]

View File

@@ -332,7 +332,6 @@ class Event(models.Model, RevisionMixin):
# Monies # Monies
payment_method = models.CharField(max_length=255, blank=True, null=True) payment_method = models.CharField(max_length=255, blank=True, null=True)
payment_received = 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') collector = models.CharField(max_length=255, blank=True, null=True, verbose_name='collected by')
# Calculated values # Calculated values

View File

@@ -125,7 +125,6 @@ class EventDuplicate(EventUpdate):
old = super(EventDuplicate, self).get_object(queryset) # Get the object (the event you're duplicating) 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 = 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.based_on = old # Make the new event based on the old event
new.purchase_order = None
if self.request.method in ( if self.request.method in (
'POST', 'PUT'): # This only happens on save (otherwise items won't display in editor) 'POST', 'PUT'): # This only happens on save (otherwise items won't display in editor)

View File

@@ -148,11 +148,6 @@
{% endif %} {% endif %}
{% if event.is_rig %} {% if event.is_rig %}
{% if object.purchase_order %}
<dt>PO</dt>
<dd>{{ object.purchase_order }}</dd>
{% endif %}
<dd>&nbsp;</dd> <dd>&nbsp;</dd>
<dt>Authorised</dt> <dt>Authorised</dt>

View File

@@ -34,14 +34,6 @@
<para style="head_numbers">{{ invoice.invoice_date|date:"d/m/Y" }}</para> <para style="head_numbers">{{ invoice.invoice_date|date:"d/m/Y" }}</para>
</td> </td>
</tr> </tr>
{% if object.purchase_order %}
<tr>
<td><para style="head_titles">PO Number</para></td>
<td>
<para style="head_numbers">{{ object.purchase_order|default_if_none:"" }}</para>
</td>
</tr>
{% endif %}
</blockTable> </blockTable>
{% elif quote %} {% elif quote %}

View File

@@ -76,11 +76,6 @@
<dd>{{ object.checked_in_by.name }}</dd> <dd>{{ object.checked_in_by.name }}</dd>
{% endif %} {% endif %}
{% if object.event.purchase_order %}
<dt>PO</dt>
<dd>{{ object.event.purchase_order }}</dd>
{% endif %}
<dd>&nbsp;</dd> <dd>&nbsp;</dd>
<dt>Authorised</dt> <dt>Authorised</dt>

View File

@@ -443,7 +443,7 @@ class EventTest(LiveServerTestCase):
def testEventDuplicate(self): def testEventDuplicate(self):
testEvent = models.Event.objects.create(name="TE E1", status=models.Event.PROVISIONAL, testEvent = models.Event.objects.create(name="TE E1", status=models.Event.PROVISIONAL,
start_date=date.today() + timedelta(days=6), start_date=date.today() + timedelta(days=6),
description="start future no end", purchase_order="TESTPO") description="start future no end")
item1 = models.EventItem( item1 = models.EventItem(
event=testEvent, event=testEvent,
@@ -509,8 +509,6 @@ class EventTest(LiveServerTestCase):
infoPanel = self.browser.find_element_by_xpath('//div[contains(text(), "Event Info")]/..') infoPanel = self.browser.find_element_by_xpath('//div[contains(text(), "Event Info")]/..')
self.assertIn("N0000%d" % testEvent.pk, self.assertIn("N0000%d" % testEvent.pk,
infoPanel.find_element_by_xpath('//dt[text()="Based On"]/following-sibling::dd[1]').text) 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.browser.get(self.live_server_url + '/event/' + str(testEvent.pk)) # Go back to the old event self.browser.get(self.live_server_url + '/event/' + str(testEvent.pk)) # Go back to the old event
@@ -518,8 +516,6 @@ class EventTest(LiveServerTestCase):
infoPanel = self.browser.find_element_by_xpath('//div[contains(text(), "Event Info")]/..') infoPanel = self.browser.find_element_by_xpath('//div[contains(text(), "Event Info")]/..')
self.assertNotIn("N0000%d" % testEvent.pk, self.assertNotIn("N0000%d" % testEvent.pk,
infoPanel.find_element_by_xpath('//dt[text()="Based On"]/following-sibling::dd[1]').text) 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)
# Check the items are as they were # Check the items are as they were
table = self.browser.find_element_by_id('item-table') # ID number is known, see above table = self.browser.find_element_by_id('item-table') # ID number is known, see above