add constrain and field annual permission

This commit is contained in:
Bakry 2026-01-07 15:06:14 +03:00
parent dd525f3a81
commit dd2e746507
6 changed files with 87 additions and 4 deletions

View File

@ -3997,6 +3997,13 @@ msgstr "أنواع الاستئذانات"
msgid "Monthly Hours" msgid "Monthly Hours"
msgstr "ساعات شهرية" msgstr "ساعات شهرية"
#. module: employee_requests
#: model:ir.model.fields,field_description:employee_requests.field_hr_personal_permission_type__annual_hours
#: model_terms:ir.ui.view,arch_db:employee_requests.hr_personal_permission_type_view_form
#: model_terms:ir.ui.view,arch_db:employee_requests.hr_personal_permission_type_view_tree
msgid "Annual Hours"
msgstr "ساعات سنوية"
#. module: employee_requests #. module: employee_requests
#: code:addons/employee_requests/models/hr_personal_permission.py:0 #: code:addons/employee_requests/models/hr_personal_permission.py:0
#, python-format #, python-format
@ -4056,3 +4063,16 @@ msgstr "للأسف الموظف %s, تتجاوز ساعات العمل الإض
#, python-format #, python-format
msgid "Sorry, The Employee %s Weekend Overtime Hours Exceed The Allowed Limit %s Hours, For The Selected Period." msgid "Sorry, The Employee %s Weekend Overtime Hours Exceed The Allowed Limit %s Hours, For The Selected Period."
msgstr "للأسف الموظف %s, تتجاوز ساعات العمل الإضافية في عطلة نهاية الأسبوع الحد المسموح به %s ساعة خلال هذه الفترة." msgstr "للأسف الموظف %s, تتجاوز ساعات العمل الإضافية في عطلة نهاية الأسبوع الحد المسموح به %s ساعة خلال هذه الفترة."
#. module: employee_requests
#: code:addons/employee_requests/models/hr_personal_permission_type.py:0
msgid "Monthly Permission Hours must be less than or equal to annual Permission Hours"
msgstr "يجب أن تكون ساعات الإستئذان الشهرية أقل من أو تساوي ساعات الإستئذان السنوية"
#. module: employee_requests
#: code:addons/employee_requests/models/hr_personal_permission_type.py:0
msgid "Daily Permission Hours must be less than or equal to Monthly Permission Hours"
msgstr "يجب أن تكون ساعات الإستئذان اليومية أقل من أو يساوي ساعات الإستئذان الشهرية"

View File

@ -327,6 +327,28 @@ class HrPersonalPermission(models.Model):
if number_of_per < all_perission: if number_of_per < all_perission:
raise ValidationError(_('Sorry You Have Used All Your Permission Hours In This Month')) raise ValidationError(_('Sorry You Have Used All Your Permission Hours In This Month'))
##### Annual Hours Constraint
if item.permission_type_id.annual_hours > 0:
current_year = fields.Datetime.from_string(item.date_to or item.date_from).year
year_date_from = f'{current_year}-01-01'
year_date_to = f'{current_year}-12-31'
employee_year_permissions = self.search([
('employee_id', '=', item.employee_id.id),
('permission_type_id', '=', item.permission_type_id.id),
('state', 'not in', ('draft', 'refused')),
('date_from', '>=', year_date_from),
('date_to', '<=', year_date_to),
('id', '!=', item.id),])
annual_used_hours = sum(employee_year_permissions.mapped('duration'))
if annual_used_hours + item.duration > item.permission_type_id.annual_hours:
raise ValidationError(
_('Sorry You Have Used All Your Permission Hours In This Year'))
#####
start_date_value = datetime.strptime(str(item.date_from), "%Y-%m-%d %H:%M:%S") start_date_value = datetime.strptime(str(item.date_from), "%Y-%m-%d %H:%M:%S")
end_date = datetime.strptime(str(item.date_to), "%Y-%m-%d %H:%M:%S") end_date = datetime.strptime(str(item.date_to), "%Y-%m-%d %H:%M:%S")
if start_date_value <= end_date: if start_date_value <= end_date:

View File

@ -15,8 +15,20 @@ class HrPersonalPermissionType(models.Model):
required=True required=True
) )
active = fields.Boolean(default=True) active = fields.Boolean(default=True)
annual_hours = fields.Float()
_sql_constraints = [ _sql_constraints = [('uniq_name', 'UNIQUE(name)', _('Name should be unique!'))]
('uniq_name', 'UNIQUE(name)', _('Name should be unique!'))
] @api.constrains('monthly_hours', 'annual_hours','daily_hours')
def _check_hours(self):
for record in self:
if record.monthly_hours or record.annual_hours :
if record.monthly_hours > record.annual_hours:
raise ValidationError(
_("Monthly Permission Hours must be less than or equal to annual Permission Hours"))
if record.monthly_hours or record.daily_hours:
if record.daily_hours > record.monthly_hours:
raise ValidationError(
_("Daily Permission Hours must be less than or equal to Monthly Permission Hours"))

View File

@ -18,6 +18,7 @@
<group> <group>
<field name="daily_hours" widget="float_time" /> <field name="daily_hours" widget="float_time" />
<field name="monthly_hours" widget="float_time" /> <field name="monthly_hours" widget="float_time" />
<field name="annual_hours" widget="float_time" string="Annual Hours"/>
</group> </group>
<group> <group>
<field name="approval_by" /> <field name="approval_by" />
@ -38,6 +39,7 @@
<field name="name" /> <field name="name" />
<field name="daily_hours" widget="float_time" /> <field name="daily_hours" widget="float_time" />
<field name="monthly_hours" widget="float_time" /> <field name="monthly_hours" widget="float_time" />
<field name="annual_hours" widget="float_time" string="Annual Hours"/>
<field name="approval_by" options="{'no_create': True, 'no_open': True, 'no_create_edit': True}" /> <field name="approval_by" options="{'no_create': True, 'no_open': True, 'no_create_edit': True}" />
</tree> </tree>
</field> </field>

View File

@ -188,3 +188,9 @@ msgstr "يتم خصم نص يوم من رصيد الاجازة السنوية"
#: model:ir.model.fields,field_description:employee_requests.field_hr_personal_permission_type__monthly_hours #: model:ir.model.fields,field_description:employee_requests.field_hr_personal_permission_type__monthly_hours
msgid "Monthly Hours" msgid "Monthly Hours"
msgstr "ساعات/مرات شهرية" msgstr "ساعات/مرات شهرية"
#. module: hr_permission_holidays
#: code:addons/hr_permission_holidays/models/permission.py:0
#, python-format
msgid "Sorry You Have Used All Your Permission Hours In This Year"
msgstr "تم استخدام كل ساعات الإستئذان المسموح بها خلال هذا العــام"

View File

@ -155,6 +155,27 @@ class HrPersonalPermission(models.Model):
if number_of_per < all_perission : if number_of_per < all_perission :
raise ValidationError(_('Sorry You Have Used All Your Permission Hours In This Month')) raise ValidationError(_('Sorry You Have Used All Your Permission Hours In This Month'))
##### Annual Hours Constraint
if item.permission_type_id.annual_hours > 0:
current_year = fields.Datetime.from_string(item.date_to or item.date_from).year
year_date_from = f'{current_year}-01-01'
year_date_to = f'{current_year}-12-31'
employee_year_permissions = self.search([
('employee_id', '=', item.employee_id.id),
('permission_type_id', '=', item.permission_type_id.id),
('state', 'not in', ('draft', 'refused')),
('date_from', '>=', year_date_from),
('date_to', '<=', year_date_to),
('id', '!=', item.id),])
annual_used_hours = sum(employee_year_permissions.mapped('duration'))
if annual_used_hours + item.duration > item.permission_type_id.annual_hours:
raise ValidationError(
_('Sorry You Have Used All Your Permission Hours In This Year'))
#################
if item.duration <= 0.0: if item.duration <= 0.0:
raise ValidationError(_('This Duration Must Be Greater Than Zero')) raise ValidationError(_('This Duration Must Be Greater Than Zero'))