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
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'),
)
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):
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)
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