]> git.parisson.com Git - mezzo.git/commitdiff
[Timesheet] : add holidays + leave days fix
authorEmilie Zawadzki <zawadzki@ircam.fr>
Thu, 19 Jan 2017 20:14:14 +0000 (21:14 +0100)
committerEmilie Zawadzki <zawadzki@ircam.fr>
Thu, 19 Jan 2017 20:14:14 +0000 (21:14 +0100)
app/organization/network/api.py
app/organization/network/tests.py
app/organization/network/utils.py
requirements.txt

index 0e3428ed2af4eabb9a46ec70fe3b76303fdc643d..2261991fe50ca50209f4e32d93db10e0a9a8bc74 100644 (file)
@@ -5,6 +5,7 @@ import time
 from django.conf import settings
 from datetime import date, timedelta
 import dateutil.parser
+from pprint import pprint
 
 WEEK_DAYS = {
     1:'monday',
@@ -112,7 +113,7 @@ def increment_day_per_month(month_key, day_key, dt):
             dt[month_key][day_key] = 1
     else :
         dt[month_key] = {}
-
+        dt[month_key][day_key] = 1
     return dt
 
 
index d14f7a7fc1aa288ab192166e2a8b5c769870ce86..7b0e913e636c4aa06df49ec887b96e744deea89e 100644 (file)
@@ -213,6 +213,176 @@ class NbOfHalfDaysInPeriodPerMonthTestCase(SimpleTestCase):
         self.assertEquals(result, expected)
 
 
+class NbOfHalfDaysInPeriodPerMonthTestCase2(SimpleTestCase):
+
+    def setUp(self):
+        self.date_from = datetime.date(2016,1,1)
+        self.date_to = datetime.date(2016,12,31)
+
+    def test_nbhalf_half_days(self):
+        expected =    {
+               1:{
+                  'wednesday_pm':4,
+                  'tuesday_am':4,
+                  'thursday_am':4,
+                  'monday_am':4,
+                  'tuesday_pm':4,
+                  'friday_am':4,
+                  'wednesday_am':4,
+                  'thursday_pm':4,
+                  'friday_pm':4,
+                  'monday_pm':4
+               },
+               2:{
+                  'wednesday_pm':4,
+                  'tuesday_am':4,
+                  'thursday_am':4,
+                  'monday_am':5,
+                  'tuesday_pm':4,
+                  'friday_am':4,
+                  'wednesday_am':4,
+                  'thursday_pm':4,
+                  'friday_pm':4,
+                  'monday_pm':5
+               },
+               3:{
+                  'wednesday_pm':5,
+                  'tuesday_am':5,
+                  'thursday_am':5,
+                  'monday_am':3,
+                  'tuesday_pm':5,
+                  'friday_am':4,
+                  'wednesday_am':5,
+                  'thursday_pm':5,
+                  'friday_pm':4,
+                  'monday_pm':3
+               },
+               4:{
+                  'wednesday_pm':4,
+                  'tuesday_am':4,
+                  'thursday_am':4,
+                  'monday_am':4,
+                  'tuesday_pm':4,
+                  'friday_am':5,
+                  'wednesday_am':4,
+                  'thursday_pm':4,
+                  'friday_pm':5,
+                  'monday_pm':4
+               },
+               5:{
+                  'wednesday_pm':4,
+                  'tuesday_am':5,
+                  'thursday_am':3,
+                  'monday_am':4,
+                  'tuesday_pm':5,
+                  'friday_am':4,
+                  'wednesday_am':4,
+                  'thursday_pm':3,
+                  'friday_pm':4,
+                  'monday_pm':4
+               },
+               6:{
+                  'wednesday_pm':5,
+                  'tuesday_am':4,
+                  'thursday_am':5,
+                  'monday_am':4,
+                  'tuesday_pm':4,
+                  'friday_am':4,
+                  'wednesday_am':5,
+                  'thursday_pm':5,
+                  'friday_pm':4,
+                  'monday_pm':4
+               },
+               7:{
+                  'wednesday_pm':4,
+                  'tuesday_am':4,
+                  'thursday_am':3,
+                  'monday_am':4,
+                  'tuesday_pm':4,
+                  'friday_am':5,
+                  'wednesday_am':4,
+                  'thursday_pm':3,
+                  'friday_pm':5,
+                  'monday_pm':4
+               },
+               8:{
+                  'wednesday_pm':5,
+                  'tuesday_am':5,
+                  'thursday_am':4,
+                  'monday_am':4,
+                  'tuesday_pm':5,
+                  'friday_am':4,
+                  'wednesday_am':5,
+                  'thursday_pm':4,
+                  'friday_pm':4,
+                  'monday_pm':4
+               },
+               9:{
+                  'wednesday_pm':4,
+                  'tuesday_am':4,
+                  'thursday_am':5,
+                  'monday_am':4,
+                  'tuesday_pm':4,
+                  'friday_am':5,
+                  'wednesday_am':4,
+                  'thursday_pm':5,
+                  'friday_pm':5,
+                  'monday_pm':4
+               },
+               10:{
+                  'wednesday_pm':4,
+                  'tuesday_am':4,
+                  'thursday_am':4,
+                  'monday_am':5,
+                  'tuesday_pm':4,
+                  'friday_am':4,
+                  'wednesday_am':4,
+                  'thursday_pm':4,
+                  'friday_pm':4,
+                  'monday_pm':5
+               },
+               11:{
+                  'wednesday_pm':5,
+                  'tuesday_am':4,
+                  'thursday_am':4,
+                  'monday_am':4,
+                  'tuesday_pm':4,
+                  'friday_am':3,
+                  'wednesday_am':5,
+                  'thursday_pm':4,
+                  'friday_pm':3,
+                  'monday_pm':4
+               },
+               12:{
+                  'wednesday_pm':4,
+                  'tuesday_am':4,
+                  'thursday_am':5,
+                  'monday_am':4,
+                  'tuesday_pm':4,
+                  'friday_am':5,
+                  'wednesday_am':4,
+                  'thursday_pm':5,
+                  'friday_pm':5,
+                  'monday_pm':4
+               }
+            }
+        result = get_nb_half_days_by_period_per_month(self.date_from, self.date_to)
+        self.assertEquals(result, expected)
+
+
+class NbOfLeaveDaysPerMonthTestCase2(SimpleTestCase):
+
+    def setUp(self):
+        self.date_from = datetime.date(2016,1,1)
+        self.date_to = datetime.date(2016,1,31)
+        self.external_id = 106
+
+    def test_nb_leave_days(self):
+        expected = {}
+        result = get_leave_days_per_month(self.date_from, self.date_to, self.external_id)
+        self.assertEquals(result, expected)
+
+
 class NbOfLeaveDaysPerMonthTestCase(SimpleTestCase):
 
     def setUp(self):
index f992255a77add98ff66c9c76668b2ae507d65f93..d2fb1d8b710d3767ce1af78e87f0be98e65d3edc 100644 (file)
@@ -9,6 +9,7 @@ from django.utils import timezone
 from organization.network.api import *
 from collections import defaultdict, OrderedDict
 from pprint import pprint
+from workalendar.europe import France
 
 
 def get_nb_half_days_by_period(date_from, date_to):
@@ -47,7 +48,9 @@ def get_nb_half_days_by_period(date_from, date_to):
 
 def get_nb_half_days_by_period_per_month(date_from, date_to):
     day_list = pd.date_range(date_from, date_to).tolist()
-
+    cal = France()
+    holidays = cal.holidays(date_from.year)
+    holidays_date = [h[0] for h in holidays]
     md_dict = {}
     for i in range(1,13):
         md_dict[i] = {
@@ -65,21 +68,22 @@ def get_nb_half_days_by_period_per_month(date_from, date_to):
 
     # for each day of the period
     for day in day_list :
-        if day.dayofweek == 0:
-            md_dict[day.month]['monday_am'] += 1
-            md_dict[day.month]['monday_pm'] += 1
-        if day.dayofweek == 1:
-            md_dict[day.month]['tuesday_am'] += 1
-            md_dict[day.month]['tuesday_pm'] += 1
-        if day.dayofweek == 2:
-            md_dict[day.month]['wednesday_am'] += 1
-            md_dict[day.month]['wednesday_pm'] += 1
-        if day.dayofweek == 3:
-            md_dict[day.month]['thursday_am'] += 1
-            md_dict[day.month]['thursday_pm'] += 1
-        if day.dayofweek == 4:
-            md_dict[day.month]['friday_am'] += 1
-            md_dict[day.month]['friday_pm'] += 1
+        if not day.date() in holidays_date:
+            if day.dayofweek == 0:
+                md_dict[day.month]['monday_am'] += 1
+                md_dict[day.month]['monday_pm'] += 1
+            if day.dayofweek == 1:
+                md_dict[day.month]['tuesday_am'] += 1
+                md_dict[day.month]['tuesday_pm'] += 1
+            if day.dayofweek == 2:
+                md_dict[day.month]['wednesday_am'] += 1
+                md_dict[day.month]['wednesday_pm'] += 1
+            if day.dayofweek == 3:
+                md_dict[day.month]['thursday_am'] += 1
+                md_dict[day.month]['thursday_pm'] += 1
+            if day.dayofweek == 4:
+                md_dict[day.month]['friday_am'] += 1
+                md_dict[day.month]['friday_pm'] += 1
 
     return md_dict
 
index 0bb9877dedd0cd9e68bd863cc3928699613a0ffa..dcef1e3eb74b46d8695757ff4bba42e6fd6535e9 100644 (file)
@@ -24,3 +24,4 @@ sphinx_rtd_theme
 pandas==0.19.2
 xlwt==1.2.0
 DateTimeRange==0.2.8
+workalendar==1.0.0