aboutsummaryrefslogtreecommitdiff
path: root/app/dispatch/views.py
diff options
context:
space:
mode:
authorMitch Riedstra <mitch@riedstra.us>2018-02-03 21:17:02 -0500
committerMitch Riedstra <mitch@riedstra.us>2018-02-03 21:17:02 -0500
commit93a57dc5afb2962d675c51504ecdb3afa34a95a7 (patch)
tree97e0ffb39c777c2907f817c24a88b9696d0f6370 /app/dispatch/views.py
parent9494ff9cb0e917fb11d2281fe0ffb04a8c40b6db (diff)
downloaddispatch-tracker-93a57dc5afb2962d675c51504ecdb3afa34a95a7.tar.gz
dispatch-tracker-93a57dc5afb2962d675c51504ecdb3afa34a95a7.tar.xz
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.
Diffstat (limited to 'app/dispatch/views.py')
-rw-r--r--app/dispatch/views.py26
1 files changed, 17 insertions, 9 deletions
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']