]> err.no Git - peojumk/commitdiff
Add createinvoice/detailinvoice foo
authorTollef Fog Heen <tfheen@err.no>
Mon, 7 May 2012 09:24:39 +0000 (11:24 +0200)
committerTollef Fog Heen <tfheen@err.no>
Mon, 7 May 2012 09:24:39 +0000 (11:24 +0200)
invoice/models.py
invoice/urls.py
invoice/views.py
templates/invoice/invoice_form.html

index 8ec1945031227e4d33addba8395c92bfdb9f0f12..64f07105a843085d01288c43ad308c43889d324b 100644 (file)
@@ -34,6 +34,9 @@ class VAT(models.Model):
         verbose_name = _('VAT level')
         verbose_name_plural = _('VAT levels')
 
+    def get_invoicelines(self):
+        return self.invoiceline_set.select_related('invoice')
+
     def __unicode__(self):
         return '%s' % self.name
 
index f7b5850f600cbfee030182210b68da3060a171db..9eb3ac9fd0550be966d433fd67fbf57f66368e8c 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
+     CreateInvoice, DetailInvoice
 
 import invoice.views
 
@@ -13,4 +13,5 @@ urlpatterns = patterns('invoice.views',
                 url(r'^client/(?P<pk>\d+)/delete$', DeleteClient.as_view(), name='c_delete'),
                 url(r'^accounts/login/$', django.contrib.auth.views.login),
                 url(r'^invoice/new$', CreateInvoice.as_view(), name="invoice_new"),
+                url(r'^invoice/(?P<pk>\d+)$', DetailInvoice.as_view()),
 )
index 283ee07f0d9cd90c80848a77f8698b4230ae6bff..a7a4b31e525bb77fc590be04ca79a46eceb44cac 100644 (file)
@@ -7,7 +7,10 @@ from django.views.generic.create_update import get_model_and_form_class, apply_e
 from django.views.generic import UpdateView, DeleteView, CreateView, DetailView
 from django.utils.decorators import method_decorator
 
-from invoice.models import Client, Invoice
+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
 
 @login_required
@@ -15,6 +18,8 @@ def index(request):
     clients = Client.objects.all()
     return render_to_response('invoice/index.html', {'clients': clients})
 
+# ------------------- CLIENT ---------------
+
 class DetailClient(DetailView):
     model = Client
     @method_decorator(login_required)
@@ -47,11 +52,22 @@ class DeleteClient(DeleteView):
     @method_decorator(login_required)
     def dispatch(self, *args, **kwargs):
         return super(DeleteClient, self).dispatch(*args, **kwargs)
-    
 
 # ------------------- INVOICE ---------------
-class CreateInvoice(CreateView):
+
+class InvoiceLineInline(InlineFormSet):
+    model = InvoiceLine
+
+class DetailInvoice(DetailView):
+    model = Invoice
+
+    @method_decorator(login_required)
+    def dispatch(self, *args, **kwargs):
+        return super(DetailInvoice, self).dispatch(*args, **kwargs)
+
+class CreateInvoice(CreateWithInlinesView):
     model = Invoice
+    inlines = [InvoiceLineInline]
     form_class = InvoiceForm
     success_url = '/'
 
index 984348f5ed851225c390aefea28923fd08d42e97..f381525bf28bd64bd13776300db1baf4ca6e162f 100644 (file)
@@ -5,7 +5,10 @@
 <form id="form" enctype="multipart/form-data" method="post">
 {% csrf_token %}
 <ul>
-    {{ form.as_ul}}
+    {{ form.as_ul }}
+{% for formset in inlines %}
+<li><table>{{ formset }}</table></li>
+{% endfor %}
 </ul>
 <input type="submit">
 </form>