From 93a57dc5afb2962d675c51504ecdb3afa34a95a7 Mon Sep 17 00:00:00 2001 From: Mitch Riedstra Date: Sat, 3 Feb 2018 21:17:02 -0500 Subject: Show whether or not there are any related invoices on the summary page Also prevent the generation of duplicate invoices based on the date of invoice and the current user. --- app/dispatch/views.py | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) (limited to 'app/dispatch/views.py') diff --git a/app/dispatch/views.py b/app/dispatch/views.py index f01cb31..b27bea5 100644 --- a/app/dispatch/views.py +++ b/app/dispatch/views.py @@ -148,16 +148,24 @@ class DriverSummary(UserPassesTestMixin, LoadDateSort): stats['count'], stats['average'], stats['sum'] = (0, 0, 0) context['can_invoice'] = True + context['related_invoices'] = Invoice.objects.filter( + invoice_date__range=(context['week_dates']['start_date'], + context['week_dates']['end_date']), + user=self.request.user) + loads_by_date = context['loads'] - for d in loads_by_date: - # Iterate over the array for the given date - for l in loads_by_date[d]: - stats['count'] += 1 - stats['sum'] += l.amount - - # Any load not up to par will break the chain - if not l.can_invoice(): - context['can_invoice'] = False + if len(context['related_invoices']) >= 1: + context['can_invoice'] = False + else: + for d in loads_by_date: + # Iterate over the array for the given date + for l in loads_by_date[d]: + stats['count'] += 1 + stats['sum'] += l.amount + + # Any load not up to par will break the chain + if not l.can_invoice(): + context['can_invoice'] = False if stats['sum'] is not 0 and stats['count'] is not 0: stats['average'] = stats['sum']/stats['count'] -- cgit v1.2.3