From 131a5fb8a101fca8af05cd727bce65ba4c776a2d Mon Sep 17 00:00:00 2001 From: Tollef Fog Heen Date: Sat, 28 Jul 2012 10:48:46 +0200 Subject: [PATCH] Warn/error on overdue invoices --- invoice/models.py | 1 + invoice/views.py | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/invoice/models.py b/invoice/models.py index fc4e717..4f6634c 100644 --- a/invoice/models.py +++ b/invoice/models.py @@ -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): diff --git a/invoice/views.py b/invoice/views.py index 68f296e..9b9805b 100644 --- a/invoice/views.py +++ b/invoice/views.py @@ -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) -- 2.39.5