]> err.no Git - peojumk/commitdiff
Warn/error on overdue invoices
authorTollef Fog Heen <tfheen@err.no>
Sat, 28 Jul 2012 08:48:46 +0000 (10:48 +0200)
committerTollef Fog Heen <tfheen@err.no>
Sat, 28 Jul 2012 08:48:46 +0000 (10:48 +0200)
invoice/models.py
invoice/views.py

index fc4e7179440374ae8759ff7f19a2f49e4cb620e2..4f6634c7d1e13b0cabfc0a3c80c4d5848793a763 100644 (file)
@@ -60,6 +60,7 @@ class Invoice(models.Model):
 
     bootstrap_label = property(_bootstrap_colour)
     due_label = property(_due_label)
+    due_days = property(_due_label)
 
 
 class VAT(models.Model):
index 68f296e9bef2bafc349031a2546b5b6765531f3c..9b9805bcba5a5c9fae587e1dea2dfc03fa5cb8c9 100644 (file)
@@ -6,6 +6,7 @@ from django.template import RequestContext
 from django.views.generic.create_update import get_model_and_form_class, apply_extra_context, redirect, update_object, lookup_object, delete_object
 from django.views.generic import UpdateView, DeleteView, CreateView, DetailView
 from django.utils.decorators import method_decorator
+from django.contrib import messages
 
 from extra_views import CreateWithInlinesView, UpdateWithInlinesView, InlineFormSet
 from extra_views.generic import GenericInlineFormSet
@@ -63,6 +64,14 @@ class InvoiceLineInline(InlineFormSet):
 class DetailInvoice(DetailView):
     model = Invoice
 
+    def get(self, request, *args, **kwargs):
+        i = get_object_or_404(Invoice, pk=kwargs["pk"])
+        if i.due_days < 0:
+            messages.error(request, "This invoice is overdue")
+        elif i.due_days < 3:
+            messages.warning(request, "This invoice is soon due")
+        return super(DetailInvoice, self).get(request, *args, **kwargs)
+
     @method_decorator(login_required)
     def dispatch(self, *args, **kwargs):
         return super(DetailInvoice, self).dispatch(*args, **kwargs)