From af1396a1686d30616673ff8f35135111e61aed5f Mon Sep 17 00:00:00 2001 From: tomtom5152 Date: Fri, 30 Jan 2015 00:26:15 +0000 Subject: [PATCH] Added the ability to invoice an event --- RIGS/finance.py | 32 +++++++++- RIGS/migrations/0018_auto_20150130_0016.py | 26 ++++++++ RIGS/templates/RIGS/event_detail.html | 12 ++++ RIGS/templates/RIGS/event_invoice.html | 70 ++++++++++++++++++++++ RIGS/templates/RIGS/invoice_detail.html | 12 +++- RIGS/templates/RIGS/invoice_list.html | 19 ++++-- RIGS/urls.py | 12 ++++ 7 files changed, 177 insertions(+), 6 deletions(-) create mode 100644 RIGS/migrations/0018_auto_20150130_0016.py create mode 100644 RIGS/templates/RIGS/event_invoice.html diff --git a/RIGS/finance.py b/RIGS/finance.py index 72439d95..c8a3657d 100644 --- a/RIGS/finance.py +++ b/RIGS/finance.py @@ -3,6 +3,7 @@ from django.http import Http404, HttpResponseRedirect from django.views import generic from django.shortcuts import get_object_or_404 from django.contrib import messages +import datetime from RIGS import models @@ -25,7 +26,7 @@ class InvoiceDetail(generic.DetailView): class InvoiceVoid(generic.View): - def get(self, request, *args, **kwargs): + def get(self, *args, **kwargs): pk = kwargs.get('pk') object = get_object_or_404(models.Invoice, pk=pk) object.void = not object.void @@ -36,6 +37,35 @@ class InvoiceVoid(generic.View): return HttpResponseRedirect(reverse_lazy('invoice_detail', kwargs={'pk': object.pk})) +class InvoiceArchive(generic.ListView): + model = models.Invoice + paginate_by = 25 + + +class InvoiceWaiting(generic.ListView): + model = models.Event + paginate_by = 25 + template_name = 'RIGS/event_invoice.html' + + def get_queryset(self): + events = self.model.objects.filter(is_rig=True, end_date__lt=datetime.date.today(), + invoice__isnull=True).select_related('person', 'organisation', 'venue', + 'mic') # @todo find a way to select items + return events + + +class InvoiceEvent(generic.View): + def get(self, *args, **kwargs): + epk = kwargs.get('pk') + event = models.Event.objects.get(pk=epk) + invoice, created = models.Invoice.objects.get_or_create(event=event) + + if created: + invoice.invoice_date = datetime.date.today() + + return HttpResponseRedirect(reverse_lazy('invoice_detail', kwargs={'pk': invoice.pk})) + + class PaymentCreate(generic.CreateView): model = models.Payment diff --git a/RIGS/migrations/0018_auto_20150130_0016.py b/RIGS/migrations/0018_auto_20150130_0016.py new file mode 100644 index 00000000..67c3eb97 --- /dev/null +++ b/RIGS/migrations/0018_auto_20150130_0016.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models, migrations + + +class Migration(migrations.Migration): + dependencies = [ + ('RIGS', '0017_auto_20150129_2041'), + ] + + operations = [ + migrations.AlterField( + model_name='invoice', + name='void', + field=models.BooleanField(default=False), + preserve_default=True, + ), + migrations.AlterField( + model_name='payment', + name='method', + field=models.CharField(max_length=2, choices=[(b'C', b'Cash'), (b'I', b'Internal'), (b'E', b'External'), + (b'SU', b'SU Core')]), + preserve_default=True, + ), + ] diff --git a/RIGS/templates/RIGS/event_detail.html b/RIGS/templates/RIGS/event_detail.html index eadeaab5..9d309703 100644 --- a/RIGS/templates/RIGS/event_detail.html +++ b/RIGS/templates/RIGS/event_detail.html @@ -15,6 +15,10 @@ class="glyphicon glyphicon-print"> + {% if perms.RIGS.add_invoice %} + + {% endif %} @@ -121,6 +125,10 @@ class="glyphicon glyphicon-print"> + {% if perms.RIGS.add_invoice %} + + {% endif %}
@@ -145,6 +153,10 @@ class="glyphicon glyphicon-print"> + {% if perms.RIGS.add_invoice %} + + {% endif %}
Last edited at {{ object.last_edited_at|date:"SHORT_DATETIME_FORMAT" }} by {{ object.last_edited_by.name }}. diff --git a/RIGS/templates/RIGS/event_invoice.html b/RIGS/templates/RIGS/event_invoice.html new file mode 100644 index 00000000..c3b42807 --- /dev/null +++ b/RIGS/templates/RIGS/event_invoice.html @@ -0,0 +1,70 @@ +{% extends 'base.html' %} +{% load paginator from filters %} + +{% block title %}Events for Invoice{% endblock %} + +{% block content %} +
+

Events for Invoice

+ {% if is_paginated %} +
+ {% paginator %} +
+ {% endif %} + + + + + + + + + + + + + + {% for object in object_list %} + + + + + + + + + + {% endfor %} + +
#DateEventClientCost
{{ object.end_date }}{{ object.name }} + {% if object.organisation %} + {{ object.organisation.name }} + {% else %} + {{ object.person.name }} + {% endif %} + {{ object.sum_total|floatformat:2 }} + {{ object.mic.initials }}
+ +
+ + + +
+ {% if is_paginated %} +
+ {% paginator %} +
+ {% endif %} +
+{% endblock %} \ No newline at end of file diff --git a/RIGS/templates/RIGS/invoice_detail.html b/RIGS/templates/RIGS/invoice_detail.html index 9ce5a667..38dd4c97 100644 --- a/RIGS/templates/RIGS/invoice_detail.html +++ b/RIGS/templates/RIGS/invoice_detail.html @@ -4,7 +4,17 @@ {% block content %}
-

Invoice {{ object.pk }}

+
+
+

Invoice {{ object.pk }}

+
+ +
+ + + +
+
diff --git a/RIGS/templates/RIGS/invoice_list.html b/RIGS/templates/RIGS/invoice_list.html index ef246970..9db8feb7 100644 --- a/RIGS/templates/RIGS/invoice_list.html +++ b/RIGS/templates/RIGS/invoice_list.html @@ -1,10 +1,16 @@ {% extends 'base.html' %} +{% load paginator from filters %} -{% block title %}Active Invoices{% endblock %} +{% block title %}Invoices{% endblock %} {% block content %}
-

Active Invoices

+

Invoices

+ {% if is_paginated %} +
+ {% paginator %} +
+ {% endif %} @@ -17,8 +23,8 @@ {% for object in object_list %} - - + + @@ -31,5 +37,10 @@ {% endfor %}
{{ object.pk }}
{{ object.pk }} {{ object.event }} {{ object.invoice_date }} {{ object.balance|floatformat:2 }}
+ {% if is_paginated %} +
+ {% paginator %} +
+ {% endif %}
{% endblock %} \ No newline at end of file diff --git a/RIGS/urls.py b/RIGS/urls.py index f06e1cef..d50b78cb 100644 --- a/RIGS/urls.py +++ b/RIGS/urls.py @@ -77,10 +77,22 @@ urlpatterns = patterns('', url(r'^event/archive/$', login_required()(rigboard.EventArchive.as_view()), name='event_archive'), + # Finance url(r'^invoice/$', permission_required_with_403('RIGS.view_invoice')(finance.InvoiceIndex.as_view()), name='invoice_list'), + url(r'^invoice/archive/$', + permission_required_with_403('RIGS.view_invoice')(finance.InvoiceArchive.as_view()), + name='invoice_archive'), + url(r'^invoice/waiting/$', + permission_required_with_403('RIGS.add_invoice')(finance.InvoiceWaiting.as_view()), + name='invoice_waiting'), + + url(r'^event/(?P\d+)/invoice/$', + permission_required_with_403('RIGS.add_invoice')(finance.InvoiceEvent.as_view()), + name='invoice_event'), + url(r'^invoice/(?P\d+)/$', permission_required_with_403('RIGS.view_invoice')(finance.InvoiceDetail.as_view()), name='invoice_detail'),