Merge pull request #5822 from expsa/bakry_hr

fix Validates overtime hours workdays and weekend days
This commit is contained in:
bakry 2025-12-25 13:23:35 +03:00 committed by GitHub
commit eb77deef05
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 91 additions and 5 deletions

View File

@ -138,14 +138,20 @@
<field name="attendance_ids" attrs="{'readonly': [('state', '!=', 'draft')]}"/> <field name="attendance_ids" attrs="{'readonly': [('state', '!=', 'draft')]}"/>
</page> </page>
<page string="Overtime Settings" name="over_time_full1"> <page string="Overtime Settings" name="over_time_full1">
<group col="2">
<group> <group>
<field name="work_days" string="Work Days overtime"/> <field name="work_days" string="Work Days overtime"/>
<field name="work_hour" string="Work Hours"/> <field name="work_hour" string="Work Hours"/>
<field name="overtime_factor_daily"/> <field name="overtime_factor_daily"/>
<field name="overtime_factor_holiday"/> <field name="overtime_factor_holiday"/>
<field name="max_overtime_hour"/>
<field name="request_after_day" groups="hr.group_hr_manager,hr.group_hr_user"/> <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>
<!--group string="Overtime Accounts Settings" > <!--group string="Overtime Accounts Settings" >
<field name="journal_overtime_id" string="Journal Overtime"/> <field name="journal_overtime_id" string="Journal Overtime"/>
@ -273,6 +279,7 @@
<field name="attendance_ids" attrs="{'readonly': [('state', '!=', 'draft')]}"/> <field name="attendance_ids" attrs="{'readonly': [('state', '!=', 'draft')]}"/>
</page> </page>
<page string="Overtime Settings" name="over_time_not_full1"> <page string="Overtime Settings" name="over_time_not_full1">
<group col="2">
<group> <group>
<field name="work_days" string="Work Days overtime"/> <field name="work_days" string="Work Days overtime"/>
<field name="work_hour" string="Work Hours"/> <field name="work_hour" string="Work Hours"/>
@ -281,6 +288,13 @@
<field name="max_overtime_hour"/> <field name="max_overtime_hour"/>
<field name="request_after_day" groups="hr.group_hr_manager,hr.group_hr_user"/> <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>
<!--group string="Overtime Accounts Settings" > <!--group string="Overtime Accounts Settings" >
<field name="journal_overtime_id" string="Journal Overtime"/> <field name="journal_overtime_id" string="Journal Overtime"/>

View File

@ -4043,3 +4043,16 @@ msgstr "لايمكن إختيار نفس نوع الموظف الحالي"
#: model:ir.model.fields,field_description:employee_requests.field_hr_personal_permission__manager_id #: model:ir.model.fields,field_description:employee_requests.field_hr_personal_permission__manager_id
msgid "Direct Manager" 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 -*- # -*- coding: utf-8 -*-
from __future__ import division from __future__ import division
from datetime import datetime from datetime import datetime,timedelta
from odoo import models, fields, api, _, exceptions from odoo import models, fields, api, _, exceptions
from odoo.exceptions import UserError 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')) raise exceptions.Warning(_('Sorry, Can Not Request without The Employees'))
self.line_ids_over_time.get_max_remain_hours() self.line_ids_over_time.get_max_remain_hours()
self.chick_not_mission() self.chick_not_mission()
self._check_overtime_hours_limits()
self.state = "submit" self.state = "submit"
def direct_manager(self): def direct_manager(self):
@ -341,6 +342,51 @@ class employee_overtime_request(models.Model):
def chick_hours_calenders(self): def chick_hours_calenders(self):
self.line_ids_over_time.chick_hours_calender() 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): class HrEmployeeOverTime(models.Model):
_name = 'line.ids.over.time' _name = 'line.ids.over.time'

View File

@ -3001,7 +3001,17 @@ msgstr "متزوج"
#. module: hr_base #. module: hr_base
#: model:ir.model.fields,field_description:hr_base.field_resource_calendar__max_overtime_hour #: model:ir.model.fields,field_description:hr_base.field_resource_calendar__max_overtime_hour
msgid "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 #. module: hr_base
#: model:ir.model.fields,field_description:hr_base.field_resource_calendar__request_after_day #: model:ir.model.fields,field_description:hr_base.field_resource_calendar__request_after_day

View File

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