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/models.py | 2 +- .../templates/dispatch/drivers/summary.html | 29 +++++++++++++++++++++- app/dispatch/views.py | 26 ++++++++++++------- app/requirements.txt | 2 +- 4 files changed, 47 insertions(+), 12 deletions(-) (limited to 'app') diff --git a/app/dispatch/models.py b/app/dispatch/models.py index b0f76e5..0dde07b 100644 --- a/app/dispatch/models.py +++ b/app/dispatch/models.py @@ -58,7 +58,7 @@ class Load(models.Model): return "/loads/view/%i" % self.id def can_invoice(self): - # Prevent 0 and $1 invoices as well as loads w/o attachments + # Prevent $0 and $1 invoices as well as loads w/o attachments if self.amount >= 2 and len(self.paperwork_set.all()) >= 1: return True else: diff --git a/app/dispatch/templates/dispatch/drivers/summary.html b/app/dispatch/templates/dispatch/drivers/summary.html index 82df917..55d0854 100644 --- a/app/dispatch/templates/dispatch/drivers/summary.html +++ b/app/dispatch/templates/dispatch/drivers/summary.html @@ -91,7 +91,8 @@ -{% if not can_invoice %} + +{% if not can_invoice and related_invoices|length == 0 %}
Note:
@@ -101,6 +102,32 @@

+{% elif related_invoices|length >= 1 %} +
+
+
Note:
+

+ There are Invoices related to these loads + + + + + + + + + + + {% for r in related_invoices %} + + + + + {% endfor %} + +
Invoice NumberInvoice AmountInvoice Paid
{{r.invoice_id}}{{r.total}}{{r.paid}}View
+

+
{% endif %} 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'] diff --git a/app/requirements.txt b/app/requirements.txt index 1d1e613..c4f2f33 100644 --- a/app/requirements.txt +++ b/app/requirements.txt @@ -2,7 +2,7 @@ Django==1.11.5 django-auditlog==0.4.3 django-jsonfield==1.0.1 Faker==0.8.4 -psycopg2==2.7.3.1 +psycopg2==2.7.3.2 pyaml==17.10.0 python-dateutil==2.6.1 pytz==2017.2 -- cgit v1.2.3