From 8511f6ec7c8f2d096ee5d19d5abebc39b90ea3e8 Mon Sep 17 00:00:00 2001 From: Bakry Date: Thu, 25 Dec 2025 15:50:30 +0300 Subject: [PATCH] fix Validates overtime hours workdays and weekend days --- .../models/employee_overtime_request.py | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/odex25_hr/employee_requests/models/employee_overtime_request.py b/odex25_hr/employee_requests/models/employee_overtime_request.py index b569926f4..f4975f072 100644 --- a/odex25_hr/employee_requests/models/employee_overtime_request.py +++ b/odex25_hr/employee_requests/models/employee_overtime_request.py @@ -345,13 +345,26 @@ class employee_overtime_request(models.Model): @api.constrains('date_from', 'date_to', 'line_ids_over_time', 'exception') def _check_overtime_hours_limits(self): """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,} 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 + 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: employee = line.employee_id calendar = employee.resource_calendar_id @@ -372,10 +385,10 @@ class employee_overtime_request(models.Model): weekend_count = 0 current_date = rec.date_from while current_date <= rec.date_to: - if current_date.weekday() not in weekend_days: - workdays_count += 1 - else: + if current_date in official_dates or current_date.weekday() in weekend_days: weekend_count += 1 + else: + workdays_count += 1 current_date += timedelta(days=1) max_workdays_hours = workdays_count * calendar.max_day_hour max_weekend_hours = weekend_count * calendar.max_weekend_hour