From adf07a27c2226662ae6fd5144f5f434a47ad31fa Mon Sep 17 00:00:00 2001
From: Carlos Vega <carlos.vega@uni.lu>
Date: Fri, 24 Apr 2020 10:28:56 +0200
Subject: [PATCH] fixed issue with visit numbers in statistics
 https://git-r3lab.uni.lu/NCER-PD/scheduling-system/-/issues/333\#note_46157

---
 smash/web/forms/forms.py | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/smash/web/forms/forms.py b/smash/web/forms/forms.py
index acead32d..805f2e72 100644
--- a/smash/web/forms/forms.py
+++ b/smash/web/forms/forms.py
@@ -7,8 +7,10 @@ from django.utils.dates import MONTHS
 
 from web.models import Appointment, AppointmentType, AppointmentTypeLink, \
     Availability, ContactAttempt, FlyingTeam, Holiday, Item, \
-    StudySubject, Room, Worker, Visit, VoucherType, VoucherTypePrice
-from web.models.constants import SUBJECT_TYPE_CHOICES
+    StudySubject, Room, Worker, Visit, VoucherType, VoucherTypePrice, ConfigurationItem
+from web.models.constants import SUBJECT_TYPE_CHOICES, VISIT_SHOW_VISIT_NUMBER_FROM_ZERO
+from distutils.util import strtobool
+from web.templatetags.filters import display_visit_number
 
 """
 Possible redundancy, but if need arises, contents of forms can be easily customized
@@ -127,6 +129,16 @@ class StatisticsForm(Form):
         choices = [(-1, "all")]
         choices.extend(SUBJECT_TYPE_CHOICES.items())
         self.fields['subject_type'] = forms.ChoiceField(choices=choices, initial="-1")
+        visit_from_zero = ConfigurationItem.objects.get(type=VISIT_SHOW_VISIT_NUMBER_FROM_ZERO).value
+        #True values are y, yes, t, true, on and 1; false values are n, no, f, false, off and 0.
+        if strtobool(visit_from_zero):
+            new_choices = []
+            for value, label in visit_choices:
+                if int(value) > 0:
+                    label = display_visit_number(label)
+                new_choices.append((value, label))
+            visit_choices = new_choices
+                    
         self.fields['visit'] = forms.ChoiceField(choices=visit_choices, initial="-1")
 
 
-- 
GitLab