From 5defc9f931e5e9ded6a173ed4df377e5d1ebc1d7 Mon Sep 17 00:00:00 2001 From: Francois Lamontagne Date: Fri, 30 Jun 2017 07:32:10 -0400 Subject: [PATCH] Only active, paused, pending clients in routes view --- src/member/locale/fr/LC_MESSAGES/django.po | 14 +++++++++++++- src/member/templates/client/list.html | 4 ++++ src/member/tests.py | 11 +++++++++++ src/member/views.py | 20 +++++++++++++++----- 4 files changed, 43 insertions(+), 6 deletions(-) diff --git a/src/member/locale/fr/LC_MESSAGES/django.po b/src/member/locale/fr/LC_MESSAGES/django.po index 40db0219..70190736 100644 --- a/src/member/locale/fr/LC_MESSAGES/django.po +++ b/src/member/locale/fr/LC_MESSAGES/django.po @@ -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" diff --git a/src/member/templates/client/list.html b/src/member/templates/client/list.html index 014ac2dd..34311d1c 100644 --- a/src/member/templates/client/list.html +++ b/src/member/templates/client/list.html @@ -102,6 +102,9 @@

{% trans 'Clients' %}

{% trans 'Route' %} + {% trans 'Geolocalized' %} + + {% trans 'Last update' %} @@ -114,6 +117,7 @@

{% trans 'Clients' %}

{{ obj.get_status_display }} {{ obj.get_delivery_type_display }} {{ obj.route }} + {% if obj.is_geolocalized %} {% trans 'Yes' %} {% else %} {% trans 'No' %} {% endif %} {{ obj.member.updated_at|date:"Y/m/d H:h:m" }} {% endfor %} diff --git a/src/member/tests.py b/src/member/tests.py index d862f357..91733d9d 100644 --- a/src/member/tests.py +++ b/src/member/tests.py @@ -1,4 +1,5 @@ import json +import random from datetime import date, timedelta from decimal import Decimal @@ -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], @@ -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( diff --git a/src/member/views.py b/src/member/views.py index 5f4fbf17..a4492e4f 100644 --- a/src/member/views.py +++ b/src/member/views.py @@ -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 @@ -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' @@ -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 []):