fix Validates overtime hours workdays and weekend days

This commit is contained in:
Bakry 2025-12-25 13:19:03 +03:00
parent af40a69339
commit 5bbaa9f779
5 changed files with 91 additions and 5 deletions

View File

@ -138,15 +138,21 @@
<field name="attendance_ids" attrs="{'readonly': [('state', '!=', 'draft')]}"/>
</page>
<page string="Overtime Settings" name="over_time_full1">
<group col="2">
<group>
<field name="work_days" string="Work Days overtime"/>
<field name="work_hour" string="Work Hours"/>
<field name="overtime_factor_daily"/>
<field name="overtime_factor_holiday"/>
<field name="max_overtime_hour"/>
<field name="request_after_day" groups="hr.group_hr_manager,hr.group_hr_user"/>
</group>
<group>
<field name="max_overtime_hour"/>
<field name="max_day_hour"/>
<field name="max_weekend_hour"/>
</group>
</group>
<!--group string="Overtime Accounts Settings" >
<field name="journal_overtime_id" string="Journal Overtime"/>
<field name="account_overtime_id" string="Account Overtime"/>
@ -273,6 +279,7 @@
<field name="attendance_ids" attrs="{'readonly': [('state', '!=', 'draft')]}"/>
</page>
<page string="Overtime Settings" name="over_time_not_full1">
<group col="2">
<group>
<field name="work_days" string="Work Days overtime"/>
<field name="work_hour" string="Work Hours"/>
@ -282,6 +289,13 @@
<field name="request_after_day" groups="hr.group_hr_manager,hr.group_hr_user"/>
</group>
<group>
<field name="max_overtime_hour"/>
<field name="max_day_hour"/>
<field name="max_weekend_hour"/>
</group>
</group>
<!--group string="Overtime Accounts Settings" >
<field name="journal_overtime_id" string="Journal Overtime"/>
<field name="account_overtime_id" string="Account Overtime"/>

View File

@ -4042,4 +4042,17 @@ msgstr "لايمكن إختيار نفس نوع الموظف الحالي"
#: model:ir.model.fields,field_description:employee_requests.field_hr_clearance_form__manager_id
#: model:ir.model.fields,field_description:employee_requests.field_hr_personal_permission__manager_id
msgid "Direct Manager"
msgstr "المدير المباشر"
msgstr "المدير المباشر"
#. module: employee_requests
#: code:addons/employee_requests/models/employee_overtime_request.py:0
#, python-format
msgid "Sorry, The Employee %s Workdays Overtime Hours Exceed The Allowed Limit %s Hours, For The Selected Period."
msgstr "للأسف الموظف %s, تتجاوز ساعات العمل الإضافية اثناء الدوام الحد المسموح به %s ساعة خلال هذه الفترة."
#. module: employee_requests
#: code:addons/employee_requests/models/employee_overtime_request.py:0
#, python-format
msgid "Sorry, The Employee %s Weekend Overtime Hours Exceed The Allowed Limit %s Hours, For The Selected Period."
msgstr "للأسف الموظف %s, تتجاوز ساعات العمل الإضافية في عطلة نهاية الأسبوع الحد المسموح به %s ساعة خلال هذه الفترة."

View File

@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
from __future__ import division
from datetime import datetime
from datetime import datetime,timedelta
from odoo import models, fields, api, _, exceptions
from odoo.exceptions import UserError
@ -166,6 +166,7 @@ class employee_overtime_request(models.Model):
raise exceptions.Warning(_('Sorry, Can Not Request without The Employees'))
self.line_ids_over_time.get_max_remain_hours()
self.chick_not_mission()
self._check_overtime_hours_limits()
self.state = "submit"
def direct_manager(self):
@ -340,6 +341,51 @@ class employee_overtime_request(models.Model):
@api.onchange('overtime_plase', 'date_from', 'date_to', 'exception')
def chick_hours_calenders(self):
self.line_ids_over_time.chick_hours_calender()
@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. """
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:
continue
for line in rec.line_ids_over_time:
employee = line.employee_id
calendar = employee.resource_calendar_id
if not calendar:
continue
if calendar.is_full_day:
calendar_end = calendar.full_day_off
else:
calendar_end = calendar.shift_day_off
weekend_days = set()
for day in calendar_end:
if day.name in DAY_MAP:
weekend_days.add(DAY_MAP[day.name])
workdays_count = 0
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:
weekend_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
if line.over_time_workdays_hours > max_workdays_hours and calendar.max_day_hour > 0:
raise exceptions.Warning(_('Sorry, The Employee %s Workdays Overtime Hours Exceed The Allowed Limit %s Hours, For The Selected Period.'
)%(employee.name,max_workdays_hours))
if line.over_time_vacation_hours > max_weekend_hours and calendar.max_weekend_hour > 0:
raise exceptions.Warning(_('Sorry, The Employee %s Weekend Overtime Hours Exceed The Allowed Limit %s Hours, For The Selected Period.'
)%(employee.name,max_weekend_hours))
class HrEmployeeOverTime(models.Model):

View File

@ -3001,7 +3001,17 @@ msgstr "متزوج"
#. module: hr_base
#: model:ir.model.fields,field_description:hr_base.field_resource_calendar__max_overtime_hour
msgid "Max Overtime Hour"
msgstr "اقصي عدد ساعات"
msgstr "اقصي ساعات للشهر"
#. module: hr_base
#: model:ir.model.fields,field_description:hr_base.field_resource_calendar__max_day_hour
msgid "Max Day Hour"
msgstr "اقصي ساعات لليوم"
#. module: hr_base
#: model:ir.model.fields,field_description:hr_base.field_resource_calendar__max_weekend_hour
msgid "Max Weekend Hour"
msgstr "اقصي ساعات عطلة الإسبوع"
#. module: hr_base
#: model:ir.model.fields,field_description:hr_base.field_resource_calendar__request_after_day
@ -4893,4 +4903,4 @@ msgstr "المسمي الوظيفي للموفوض"
#. module: hr_base
#: model:ir.model.fields,field_description:hr_base.field_res_company__authorized_signatory_id
msgid "Authorized Signatory"
msgstr "الموظف المفوض بالتوقيع"
msgstr "الموظف المفوض بالتوقيع"

View File

@ -939,6 +939,9 @@ class HrAttendances(models.Model):
transfer_by_emp_type = fields.Boolean('Transfer By Emp Type')
account_ids = fields.One2many('hr.overtim.accounts', 'overtim_id')
max_day_hour = fields.Float()
max_weekend_hour = fields.Float()
#get account IDs base on Overtim Employees Type account config
def get_debit_overtim_account_id(self, emp_type):
if not self.transfer_by_emp_type : return self.account_overtime_id