aboutsummaryrefslogtreecommitdiff
path: root/app/dispatch/views.py
diff options
context:
space:
mode:
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']