]> err.no Git - peojumk/commitdiff
Colour invoices on front page, add some links
authorTollef Fog Heen <tfheen@err.no>
Thu, 7 Jun 2012 15:36:41 +0000 (17:36 +0200)
committerTollef Fog Heen <tfheen@err.no>
Thu, 7 Jun 2012 15:36:41 +0000 (17:36 +0200)
invoice/models.py
invoice/urls.py
templates/invoice/index.html

index 9dd86292746a3cb9dc85818b3759edf85874c0b6..8e5a1cac45ee777380d5b9f631ca47af616ae324 100644 (file)
@@ -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)
index 0ccdd54081beb0db305eee9901cb7df70ae05905..f667fbdf01a62b93f8342b606ac331ce3f1937ff 100644 (file)
@@ -14,5 +14,5 @@ urlpatterns = patterns('invoice.views',
                 url(r'^client/(?P<pk>\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<pk>\d+)$', DetailInvoice.as_view()),
+                url(r'^invoice/(?P<pk>\d+)$', DetailInvoice.as_view(), name='invoice_view'),
 )
index 4b268b8b757a77e4e94730726b50f0f629f2bb06..432ec2fce1dbd293d1c69e965138984c4f198f8e 100644 (file)
@@ -7,12 +7,22 @@
 
 <table>
 <tr>
+  <th>Due in # days</th>
+  <th>Invoice #</td>
   <th>Date</td>
   <th>Customer</td>
   <th>Total sum</td>
 </tr>
 {% for i in new_invoices %}
 <tr>
+  <td>
+    <a href="{% url invoice:invoice_view i.id %}">
+      <span class="label {{ i.bootstrap_label }}">
+       {{ i.due_label }}
+      </span>
+    </a>
+  </td>
+  <td>{{ i.id }}</td>
   <td>{{ i.date }}</td>
   <td>{{ i.customer }}</td>
   <td>{{ i.currency }} {{ i.total_sum }}</td>