Skip to content

Commit

Permalink
Only active, paused, pending clients in routes view
Browse files Browse the repository at this point in the history
  • Loading branch information
lamontfr committed Jun 30, 2017
1 parent bbc3954 commit 5defc9f
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 6 deletions.
14 changes: 13 additions & 1 deletion src/member/locale/fr/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -903,9 +903,21 @@ msgstr ""
msgid "Last update"
msgstr "Dernière modification"

#: member/templates/client/list.html
msgid "Is the client address geolocalized ?"
msgstr "Est-ce que l'adresse du client est géolocalisée ?"

#: member/templates/client/list.html
msgid "Yes"
msgstr "Oui"

#: member/templates/client/list.html
msgid "No"
msgstr "Non"

#: member/templates/client/list.html
msgid "Last modification of the file."
msgstr ""
msgstr "Dernière modification du dossier."

#: member/templates/client/list.html
msgid "of"
Expand Down
4 changes: 4 additions & 0 deletions src/member/templates/client/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ <h1 class="ui header">{% trans 'Clients' %}</h1>
<th class="">{% trans 'Route' %}
<i class="help-text question grey icon link" data-content="{% trans 'The delivery route for the client.' %}"></i>
</th>
<th class="">{% trans 'Geolocalized' %}
<i class="help-text question grey icon link" data-content="{% trans 'Is the client address geolocalized ?' %}"></i>
</th>
<th class="">{% trans 'Last update' %}
<i class="help-text question grey icon link" data-content="{% trans 'Last modification of the file.' %}"></i>
</th>
Expand All @@ -114,6 +117,7 @@ <h1 class="ui header">{% trans 'Clients' %}</h1>
<td>{{ obj.get_status_display }}</td>
<td>{{ obj.get_delivery_type_display }}</td>
<td>{{ obj.route }}</td>
<td>{% if obj.is_geolocalized %} {% trans 'Yes' %} {% else %} {% trans 'No' %} {% endif %}</td>
<td>{{ obj.member.updated_at|date:"Y/m/d H:h:m" }}</td>
</tr>
{% endfor %}
Expand Down
11 changes: 11 additions & 0 deletions src/member/tests.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
import random

from datetime import date, timedelta
from decimal import Decimal
Expand Down Expand Up @@ -3607,6 +3608,11 @@ def test_parsing_client_id_sequence(self):
10,
route=route
)
for client in clients_on_route:
client.status = \
[Client.PAUSED, Client.ACTIVE, Client.PENDING][
random.randint(0, 2)]
client.save()
clients_organised = (
clients_on_route[1], clients_on_route[3],
clients_on_route[5], clients_on_route[7],
Expand Down Expand Up @@ -3732,6 +3738,11 @@ def test_client_numbers_should_be_the_same(self):
clients = ClientFactory.create_batch(
10,
route=route)
for client in clients:
client.status = \
[Client.PAUSED, Client.ACTIVE, Client.PENDING][
random.randint(0, 2)]
client.save()

self.force_login()
url = reverse(
Expand Down
20 changes: 15 additions & 5 deletions src/member/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from django.http import HttpResponseBadRequest
from django.urls import reverse_lazy, reverse
from django.db import transaction
from django.db.models import Q, Prefetch, Count
from django.db.models import Q, Prefetch, When, Case, Sum, IntegerField
from django.db.transaction import atomic
from django.http import HttpResponseRedirect, JsonResponse, HttpResponse
from django.shortcuts import get_object_or_404
Expand Down Expand Up @@ -1371,7 +1371,15 @@ class RouteListView(
context_object_name = 'routes'
model = Route
queryset = Route.objects.all().annotate(
client_count=Count('client')
client_count=Sum(
Case(
When(client__status__in=[
Client.PENDING, Client.ACTIVE, Client.PAUSED],
then=1),
default=0,
output_field=IntegerField()
)
)
)
permission_required = 'sous_chef.read'
template_name = 'route/list.html'
Expand All @@ -1385,9 +1393,11 @@ def get_clients_on_route(route):
Returns a list of client instances with an extra attribute
`has_been_configured`, ordered by configured then unconfigured.
"""
clients = Client.objects.filter(
route=route
).select_related('member', 'member__address')
clients = Client.objects. \
filter(route=route,
status__in=[
Client.PENDING, Client.ACTIVE, Client.PAUSED]). \
select_related('member', 'member__address')
clients_dict = {client.pk: client for client in clients}
clients_on_route = []
for client_pk in (route.client_id_sequence or []):
Expand Down

0 comments on commit 5defc9f

Please sign in to comment.