diff options
| -rw-r--r-- | app/dispatch/models.py | 2 | ||||
| -rw-r--r-- | app/dispatch/templates/dispatch/drivers/summary.html | 29 | ||||
| -rw-r--r-- | app/dispatch/views.py | 26 | ||||
| -rw-r--r-- | app/requirements.txt | 2 |
4 files changed, 47 insertions, 12 deletions
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 @@ </div> </div> -{% if not can_invoice %} + +{% if not can_invoice and related_invoices|length == 0 %} <div class="row"> <div class="col s12"> <h5>Note:</h5> @@ -101,6 +102,32 @@ </p> </div> </div> +{% elif related_invoices|length >= 1 %} +<div class="row"> + <div class="col s12"> + <h5>Note:</h5> + <p class="flow-text"> + There are Invoices related to these loads + <table> + <thead> + <tr> + <td>Invoice Number</td> + <td>Invoice Amount</td> + <td>Invoice Paid</td> + <td></td> + </tr> + </thead> + <tr> + {% for r in related_invoices %} + <td>{{r.invoice_id}}</td> + <td>{{r.total}}</td> + <td>{{r.paid}}</td> + <td class="right-align"><a class="btn blue" href="{% url 'invoice_detail' r.id%}">View</a></td> + {% endfor %} + </tr> + </table> + </div> +</div> {% 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 |
