From: Emilie Zawadzki Date: Thu, 19 Jan 2017 20:14:14 +0000 (+0100) Subject: [Timesheet] : add holidays + leave days fix X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=e7b5ed5575ce1a235577d71d77027beec132923a;p=mezzo.git [Timesheet] : add holidays + leave days fix --- diff --git a/app/organization/network/api.py b/app/organization/network/api.py index 0e3428ed..2261991f 100644 --- a/app/organization/network/api.py +++ b/app/organization/network/api.py @@ -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 diff --git a/app/organization/network/tests.py b/app/organization/network/tests.py index d14f7a7f..7b0e913e 100644 --- a/app/organization/network/tests.py +++ b/app/organization/network/tests.py @@ -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): diff --git a/app/organization/network/utils.py b/app/organization/network/utils.py index f992255a..d2fb1d8b 100644 --- a/app/organization/network/utils.py +++ b/app/organization/network/utils.py @@ -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 diff --git a/requirements.txt b/requirements.txt index 0bb9877d..dcef1e3e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -24,3 +24,4 @@ sphinx_rtd_theme pandas==0.19.2 xlwt==1.2.0 DateTimeRange==0.2.8 +workalendar==1.0.0