From 14fc50ba844330471c6e6494d00790c55bd465df Mon Sep 17 00:00:00 2001 From: Tollef Fog Heen Date: Sat, 9 Jun 2012 20:54:36 +0200 Subject: [PATCH] Add support for dumping invoices as text --- invoice/urls.py | 3 ++- invoice/views.py | 6 +++++ templates/invoice/invoice_detail.txt | 34 ++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 templates/invoice/invoice_detail.txt diff --git a/invoice/urls.py b/invoice/urls.py index f667fbd..f4781a5 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 + CreateInvoice, DetailInvoice, invoice_text import invoice.views @@ -15,4 +15,5 @@ urlpatterns = patterns('invoice.views', url(r'^accounts/login/$', django.contrib.auth.views.login), 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+)/text$', invoice_text, name='invoice_view'), ) diff --git a/invoice/views.py b/invoice/views.py index 1fdee68..32f38c2 100644 --- a/invoice/views.py +++ b/invoice/views.py @@ -20,6 +20,12 @@ def index(request): sent_invoices = Invoice.objects.filter(status = 'S') return render_to_response('invoice/index.html', locals()) +@login_required +def invoice_text(request, pk): + invoice = Invoice.objects.get(pk = pk) + + return render_to_response('invoice/invoice_detail.txt', locals(), mimetype="text/plain") + # ------------------- CLIENT --------------- class DetailClient(DetailView): diff --git a/templates/invoice/invoice_detail.txt b/templates/invoice/invoice_detail.txt new file mode 100644 index 0000000..5e36782 --- /dev/null +++ b/templates/invoice/invoice_detail.txt @@ -0,0 +1,34 @@ +INVOICE +------------------------------------------------------------------------------ +err.no AS +Disengrenda 5b +0587 Oslo +Norway + +Transfer to: +Account number (IBAN) : NO5915032765650 + +Branch Address: +DNB ASA +0021 Oslo +Norway +Phone: +47 73 58 21 01 + +SWIFT Code: DNBANOKK / DNBANOKKXXX +------------------------------------------------------------------------------ +Charge to: + +{{ invoice.customer.name }} +{{ invoice.customer.address }} + +------------------------------------------------------------------------------ +Invoice # {{ invoice.id }} +Date: {{ invoice.date|date:"Y-m-d"}} +------------------------------------------------------------------------------ +Description Hours Rate Sum +------------------------------------------------------------------------------ +{% for line in invoice.invoiceline_set.all %}{{ line.description|ljust:"30" }}{{ line.time|rjust:"5" }} {{ line.hourly_rate|rjust:"5" }}{{ line.amount|rjust:"9" }}{% endfor %} + +{{ invoice.comment }} +------------------------------------------------------------------------------ +Total: {{ invoice.currency }} {{ invoice.total_sum }} -- 2.39.5