From: Tollef Fog Heen Date: Wed, 1 Aug 2012 18:38:06 +0000 (+0200) Subject: Make it possible to mark invoices as sent and paid X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=58f32fc2a7337c8db1ade8a86bf025665504ca42;p=peojumk Make it possible to mark invoices as sent and paid --- diff --git a/invoice/urls.py b/invoice/urls.py index 92067aa..f062cc8 100644 --- a/invoice/urls.py +++ b/invoice/urls.py @@ -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\d+)$', DetailInvoice.as_view(), name='invoice_view'), url(r'^invoice/(?P\d+)/print$', DetailInvoicePrint.as_view(), name='invoice_print_view'), + url(r'^invoice/(?P\d+)/edit$', UpdateInvoice.as_view(), name='invoice_update'), ) diff --git a/invoice/views.py b/invoice/views.py index c1b2d69..84e628e 100644 --- a/invoice/views.py +++ b/invoice/views.py @@ -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