From: Tollef Fog Heen Date: Thu, 7 Jun 2012 15:36:41 +0000 (+0200) Subject: Colour invoices on front page, add some links X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=82fbe2e53e5f52d722d34fd6f36140f30a2ae564;p=peojumk Colour invoices on front page, add some links --- diff --git a/invoice/models.py b/invoice/models.py index 9dd8629..8e5a1ca 100644 --- a/invoice/models.py +++ b/invoice/models.py @@ -17,6 +17,19 @@ INVOICE_STATUS_CHOICES = ( ('P', 'Paid'), ) +# Mapping from colours to bootstrap names +BOOTSTRAP_COLOUR_MAP = { + 'red': 'label-important', + 'orange':'label-warning', + 'green':'label-success', + 'grey':'', + 'blue':'label-info', + 'black':'label-inverse', + +} + +from datetime import date + class Invoice(models.Model): """An invoice""" customer = models.ForeignKey(Client) @@ -28,9 +41,26 @@ class Invoice(models.Model): def _total_sum(self): return self.invoiceline_set.aggregate(total=Sum("amount"))["total"] - total_sum = property(_total_sum) + # represents how due the invoice is + def _bootstrap_colour(self): + delta = self.due_date - date.today() + if delta.days > 10: + return BOOTSTRAP_COLOUR_MAP['green'] + elif delta.days > 0: + return BOOTSTRAP_COLOUR_MAP['orange'] + else: + return BOOTSTRAP_COLOUR_MAP['red'] + + def _due_label(self): + delta = self.due_date - date.today() + return delta.days + + bootstrap_label = property(_bootstrap_colour) + due_label = property(_due_label) + + class VAT(models.Model): """ Model representing different taxes to be used in Invoices""" name = models.CharField(_('name'), max_length=255) diff --git a/invoice/urls.py b/invoice/urls.py index 0ccdd54..f667fbd 100644 --- a/invoice/urls.py +++ b/invoice/urls.py @@ -14,5 +14,5 @@ urlpatterns = patterns('invoice.views', url(r'^client/(?P\d+)/invoice_new$', CreateInvoice.as_view(), name='invoice_new_id'), 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()), + url(r'^invoice/(?P\d+)$', DetailInvoice.as_view(), name='invoice_view'), ) diff --git a/templates/invoice/index.html b/templates/invoice/index.html index 4b268b8..432ec2f 100644 --- a/templates/invoice/index.html +++ b/templates/invoice/index.html @@ -7,12 +7,22 @@ + + {% for i in new_invoices %} + +
Due in # daysInvoice # Date Customer Total sum
+ + + {{ i.due_label }} + + + {{ i.id }} {{ i.date }} {{ i.customer }} {{ i.currency }} {{ i.total_sum }}