mirror of
https://github.com/nottinghamtec/PyRIGS.git
synced 2026-01-17 05:22:16 +00:00
Remove Event.purchase_order in favour of a simple EventAuthorisation object.
This commit is contained in:
@@ -140,7 +140,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):
|
||||
|
||||
47
RIGS/migrations/0028_migrate_purchase_order.py
Normal file
47
RIGS/migrations/0028_migrate_purchase_order.py
Normal 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')
|
||||
]
|
||||
@@ -332,7 +332,6 @@ 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')
|
||||
|
||||
# Calculated values
|
||||
|
||||
@@ -125,7 +125,6 @@ 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
|
||||
|
||||
if self.request.method in (
|
||||
'POST', 'PUT'): # This only happens on save (otherwise items won't display in editor)
|
||||
|
||||
@@ -148,11 +148,6 @@
|
||||
{% endif %}
|
||||
|
||||
{% if event.is_rig %}
|
||||
{% if object.purchase_order %}
|
||||
<dt>PO</dt>
|
||||
<dd>{{ object.purchase_order }}</dd>
|
||||
{% endif %}
|
||||
|
||||
<dd> </dd>
|
||||
|
||||
<dt>Authorised</dt>
|
||||
|
||||
@@ -34,14 +34,6 @@
|
||||
<para style="head_numbers">{{ invoice.invoice_date|date:"d/m/Y" }}</para>
|
||||
</td>
|
||||
</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>
|
||||
|
||||
{% elif quote %}
|
||||
|
||||
@@ -76,11 +76,6 @@
|
||||
<dd>{{ object.checked_in_by.name }}</dd>
|
||||
{% endif %}
|
||||
|
||||
{% if object.event.purchase_order %}
|
||||
<dt>PO</dt>
|
||||
<dd>{{ object.event.purchase_order }}</dd>
|
||||
{% endif %}
|
||||
|
||||
<dd> </dd>
|
||||
|
||||
<dt>Authorised</dt>
|
||||
|
||||
@@ -443,7 +443,7 @@ class EventTest(LiveServerTestCase):
|
||||
def testEventDuplicate(self):
|
||||
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")
|
||||
description="start future no end")
|
||||
|
||||
item1 = models.EventItem(
|
||||
event=testEvent,
|
||||
@@ -509,8 +509,6 @@ class EventTest(LiveServerTestCase):
|
||||
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.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")]/..')
|
||||
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)
|
||||
|
||||
# Check the items are as they were
|
||||
table = self.browser.find_element_by_id('item-table') # ID number is known, see above
|
||||
|
||||
Reference in New Issue
Block a user