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