]> err.no Git - peojumk/commitdiff
Make it possible to mark invoices as sent and paid
authorTollef Fog Heen <tfheen@err.no>
Wed, 1 Aug 2012 18:38:06 +0000 (20:38 +0200)
committerTollef Fog Heen <tfheen@err.no>
Wed, 1 Aug 2012 18:38:06 +0000 (20:38 +0200)
invoice/urls.py
invoice/views.py

index 92067aacdcde8befeba9947d05f3aaa07a47805b..f062cc8eff12bdb20f71804a3141a760ce76425a 100644 (file)
@@ -1,7 +1,7 @@
 from django.conf.urls import patterns, include, url
 import django.contrib.auth.views
 from invoice.views import UpdateClient, DeleteClient, CreateClient, DetailClient, \
-     CreateInvoice, DetailInvoice, DetailInvoicePrint
+     CreateInvoice, DetailInvoice, DetailInvoicePrint, UpdateInvoice
 
 import invoice.views
 
@@ -16,4 +16,5 @@ urlpatterns = patterns('invoice.views',
                 url(r'^invoice/new$', CreateInvoice.as_view(), name="invoice_new"),
                 url(r'^invoice/(?P<pk>\d+)$', DetailInvoice.as_view(), name='invoice_view'),
                 url(r'^invoice/(?P<pk>\d+)/print$', DetailInvoicePrint.as_view(), name='invoice_print_view'),
+                url(r'^invoice/(?P<pk>\d+)/edit$', UpdateInvoice.as_view(), name='invoice_update'),
 )
index c1b2d6950b2cee06f9f139c866e7fa72c300b88c..84e628ecbf547a7cc6d0206dfb9ec918b234349e 100644 (file)
@@ -11,8 +11,8 @@ from django.contrib import messages
 from extra_views import CreateWithInlinesView, UpdateWithInlinesView, InlineFormSet
 from extra_views.generic import GenericInlineFormSet
 
-from invoice.models import Client, Invoice, InvoiceLine
-from invoice.forms import ClientForm, InvoiceForm
+from invoice.models import Client, Invoice, InvoiceLine, status_text
+from invoice.forms import ClientForm, InvoiceForm, InvoiceUpdateForm
 
 @login_required
 def index(request):
@@ -71,6 +71,16 @@ class DetailInvoice(DetailView):
             context_data.update({'alert_error': "This invoice is overdue" })
         elif self.object.due_days < 3 and self.object.status != 'P':
             context_data.update({'alert_warning': "This invoice is soon due"})
+
+        if self.object.status == 'N':
+            context_data.update({'nextstate': "S",
+                                 'nextstate_str': "sent"})
+        elif self.object.status == 'S':
+            context_data.update({'nextstate': "P",
+                                 'nextstate_str': "paid"})
+        else:
+            pass
+
         return context_data
 
     @method_decorator(login_required)
@@ -90,6 +100,19 @@ class CreateInvoice(CreateWithInlinesView):
     def dispatch(self, *args, **kwargs):
         return super(CreateInvoice, self).dispatch(*args, **kwargs)
 
+class UpdateInvoice(UpdateView):
+    model = Invoice
+    form_class = InvoiceUpdateForm
+
+    @method_decorator(login_required)
+    def dispatch(self, *args, **kwargs):
+        return super(UpdateInvoice, self).dispatch(*args, **kwargs)
+
+    def form_valid(self, form):
+        messages.info(self.request, 'Status set to %s.' % (status_text(form.data['status']), ))
+        return super(UpdateInvoice, self).form_valid(form)
+        
+
 #    def get_initial(self):
 #        initial = super(CreateInvoice, self).get_initial().copy()
 #        if self.request.path