Merge pull request #5831 from expsa/bakry_hr

fix Validates overtime hours workdays and weekend days
This commit is contained in:
bakry 2025-12-25 15:54:43 +03:00 committed by GitHub
commit 656fa27c7f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 18 additions and 5 deletions

View File

@ -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