[FIX] hr_holidays: fix gray color on saturday/sunday not working with other language than English

Instead of checking that the day short name is effectively Sat or Sun
it now checks that it is the saturday or sunday based on weekday. It is
located in a method to ease inheritance or implementation of specific
behavior based on some calendar if necessary.

Closes #17294 .
This commit is contained in:
Florent de Labarre
2017-06-02 17:19:57 +02:00
committed by Thibault Delavallée
parent 54e469c41d
commit 9675c0fcfb
@@ -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']