diff --git a/addons/hr_holidays/report/holidays_summary_report.py b/addons/hr_holidays/report/holidays_summary_report.py index 3fcff6838f1..d77e664c9e9 100644 --- a/addons/hr_holidays/report/holidays_summary_report.py +++ b/addons/hr_holidays/report/holidays_summary_report.py @@ -1,6 +1,8 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. +import calendar + from datetime import timedelta from dateutil.relativedelta import relativedelta from odoo import api, fields, models @@ -16,12 +18,15 @@ class HrHolidaySummaryReport(models.AbstractModel): 'end_date': fields.Date.to_string(st_date + relativedelta(days=59)), 'holiday_type': 'Confirmed and Approved' if holiday_type == 'both' else holiday_type } + + def _date_is_day_off(self, date): + return date.weekday() in (calendar.SATURDAY, calendar.SUNDAY,) def _get_day(self, start_date): res = [] start_date = fields.Date.from_string(start_date) for x in range(0, 60): - color = '#ababab' if start_date.strftime('%a') == 'Sat' or start_date.strftime('%a') == 'Sun' else '' + color = '#ababab' if self._date_is_day_off(start_date) else '' res.append({'day_str': start_date.strftime('%a'), 'day': start_date.day , 'color': color}) start_date = start_date + relativedelta(days=1) return res @@ -48,7 +53,7 @@ class HrHolidaySummaryReport(models.AbstractModel): for index in range(0, 60): current = start_date + timedelta(index) res.append({'day': current.day, 'color': ''}) - if current.strftime('%a') == 'Sat' or current.strftime('%a') == 'Sun': + if self._date_is_day_off(current) : res[index]['color'] = '#ababab' # count and get leave summary details. holiday_type = ['confirm','validate'] if holiday_type == 'both' else ['confirm'] if holiday_type == 'Confirmed' else ['validate']