fix Validates overtime hours workdays and weekend days
This commit is contained in:
parent
5bbaa9f779
commit
8511f6ec7c
|
|
@ -345,13 +345,26 @@ class employee_overtime_request(models.Model):
|
||||||
@api.constrains('date_from', 'date_to', 'line_ids_over_time', 'exception')
|
@api.constrains('date_from', 'date_to', 'line_ids_over_time', 'exception')
|
||||||
def _check_overtime_hours_limits(self):
|
def _check_overtime_hours_limits(self):
|
||||||
"""Validates overtime hours against calendar limits for workdays and weekend days
|
"""Validates overtime hours against calendar limits for workdays and weekend days
|
||||||
within the selected period. """
|
or official holidays within the selected period. """
|
||||||
|
|
||||||
DAY_MAP = {'monday': 0,'Tuesday': 1,'wednesday': 2,'thursday': 3,'friday': 4,'saturday': 5,'sunday': 6,}
|
DAY_MAP = {'monday': 0,'Tuesday': 1,'wednesday': 2,'thursday': 3,'friday': 4,'saturday': 5,'sunday': 6,}
|
||||||
for rec in self:
|
for rec in self:
|
||||||
if not rec.date_from or not rec.date_to or rec.exception==True:
|
if not rec.date_from or not rec.date_to or rec.exception:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
official_holidays = self.env['hr.holiday.officials'].search([
|
||||||
|
('active', '=', True),
|
||||||
|
('state', '=', 'confirm'),
|
||||||
|
('date_from', '<=', rec.date_to),
|
||||||
|
('date_to', '>=', rec.date_from),])
|
||||||
|
|
||||||
|
official_dates = set()
|
||||||
|
for hol in official_holidays:
|
||||||
|
d = hol.date_from
|
||||||
|
while d <= hol.date_to:
|
||||||
|
official_dates.add(d)
|
||||||
|
d += timedelta(days=1)
|
||||||
|
|
||||||
for line in rec.line_ids_over_time:
|
for line in rec.line_ids_over_time:
|
||||||
employee = line.employee_id
|
employee = line.employee_id
|
||||||
calendar = employee.resource_calendar_id
|
calendar = employee.resource_calendar_id
|
||||||
|
|
@ -372,10 +385,10 @@ class employee_overtime_request(models.Model):
|
||||||
weekend_count = 0
|
weekend_count = 0
|
||||||
current_date = rec.date_from
|
current_date = rec.date_from
|
||||||
while current_date <= rec.date_to:
|
while current_date <= rec.date_to:
|
||||||
if current_date.weekday() not in weekend_days:
|
if current_date in official_dates or current_date.weekday() in weekend_days:
|
||||||
workdays_count += 1
|
|
||||||
else:
|
|
||||||
weekend_count += 1
|
weekend_count += 1
|
||||||
|
else:
|
||||||
|
workdays_count += 1
|
||||||
current_date += timedelta(days=1)
|
current_date += timedelta(days=1)
|
||||||
max_workdays_hours = workdays_count * calendar.max_day_hour
|
max_workdays_hours = workdays_count * calendar.max_day_hour
|
||||||
max_weekend_hours = weekend_count * calendar.max_weekend_hour
|
max_weekend_hours = weekend_count * calendar.max_weekend_hour
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue