[FIX] hr_holidays: validity constraint
- Create a leave type valid from June 1st - Create a leave in May using the created leave type Nothing prevents the user to do it. It is because the constraint is implemented only if there is a validity start and end date. Fixes #32107 opw-2009800 closes odoo/odoo#34225 Signed-off-by: Nicolas Martinelli (nim) <nim@odoo.com>
This commit is contained in:
@@ -2475,14 +2475,26 @@ msgid "You can not have 2 leaves that overlaps on the same day."
|
||||
msgstr ""
|
||||
|
||||
#. module: hr_holidays
|
||||
#: code:addons/hr_holidays/models/hr_leave.py:463
|
||||
#: code:addons/hr_holidays/models/hr_leave.py:520
|
||||
#, python-format
|
||||
msgid "You can take %s from %s"
|
||||
msgstr ""
|
||||
|
||||
#. module: hr_holidays
|
||||
#: code:addons/hr_holidays/models/hr_leave.py:515
|
||||
#, python-format
|
||||
msgid "You can take %s only between %s and %s"
|
||||
msgstr ""
|
||||
|
||||
#. module: hr_holidays
|
||||
#: code:addons/hr_holidays/models/hr_leave.py:511
|
||||
#: code:addons/hr_holidays/models/hr_leave_allocation.py:354
|
||||
#: code:addons/hr_holidays/models/hr_leave.py:525
|
||||
#, python-format
|
||||
msgid "You can take %s until %s"
|
||||
msgstr ""
|
||||
|
||||
#. module: hr_holidays
|
||||
#: code:addons/hr_holidays/models/hr_leave.py:576
|
||||
#: code:addons/hr_holidays/models/hr_leave_allocation.py:379
|
||||
#, python-format
|
||||
msgid "You cannot delete a leave which is in %s state."
|
||||
msgstr ""
|
||||
@@ -2506,10 +2518,13 @@ msgstr ""
|
||||
msgid "day(s)"
|
||||
msgstr ""
|
||||
|
||||
#. module: hr_holidays
|
||||
#: code:addons/hr_holidays/models/hr_leave_allocation.py:222
|
||||
#: model_terms:ir.ui.view,arch_db:hr_holidays.hr_leave_allocation_view_kanban
|
||||
#: model_terms:ir.ui.view,arch_db:hr_holidays.hr_leave_report_kanban
|
||||
#: model_terms:ir.ui.view,arch_db:hr_holidays.hr_leave_view_kanban
|
||||
#: model_terms:ir.ui.view,arch_db:hr_holidays.view_employee_form_leave_inherit
|
||||
#, python-format
|
||||
msgid "days"
|
||||
msgstr ""
|
||||
|
||||
@@ -2519,12 +2534,17 @@ msgid "e.g. Report to the next month..."
|
||||
msgstr ""
|
||||
|
||||
#. module: hr_holidays
|
||||
#: code:addons/hr_holidays/models/hr_leave.py:392
|
||||
#: code:addons/hr_holidays/models/hr_leave_allocation.py:219
|
||||
#: code:addons/hr_holidays/models/hr_leave.py:398
|
||||
#, python-format
|
||||
msgid "hour(s)"
|
||||
msgstr ""
|
||||
|
||||
#. module: hr_holidays
|
||||
#: code:addons/hr_holidays/models/hr_leave_allocation.py:222
|
||||
#, python-format
|
||||
msgid "hours"
|
||||
msgstr ""
|
||||
|
||||
#. module: hr_holidays
|
||||
#: model_terms:ir.ui.view,arch_db:hr_holidays.report_holidayssummary
|
||||
msgid "of the"
|
||||
|
||||
@@ -505,16 +505,25 @@ class HolidaysRequest(models.Model):
|
||||
@api.constrains('holiday_status_id', 'date_to', 'date_from')
|
||||
def _check_leave_type_validity(self):
|
||||
for leave in self:
|
||||
vstart = leave.holiday_status_id.validity_start
|
||||
vstop = leave.holiday_status_id.validity_stop
|
||||
dfrom = leave.date_from
|
||||
dto = leave.date_to
|
||||
if leave.holiday_status_id.validity_start and leave.holiday_status_id.validity_stop:
|
||||
vstart = leave.holiday_status_id.validity_start
|
||||
vstop = leave.holiday_status_id.validity_stop
|
||||
dfrom = leave.date_from
|
||||
dto = leave.date_to
|
||||
|
||||
if dfrom and dto and (dfrom.date() < vstart or dto.date() > vstop):
|
||||
raise UserError(
|
||||
_('You can take %s only between %s and %s') % (
|
||||
leave.holiday_status_id.display_name, leave.holiday_status_id.validity_start, leave.holiday_status_id.validity_stop))
|
||||
elif leave.holiday_status_id.validity_start:
|
||||
if dfrom and (dfrom.date() < vstart):
|
||||
raise UserError(
|
||||
_('You can take %s from %s') % (
|
||||
leave.holiday_status_id.display_name, leave.holiday_status_id.validity_start))
|
||||
elif leave.holiday_status_id.validity_stop:
|
||||
if dto and (dto.date() > vstop):
|
||||
raise UserError(
|
||||
_('You can take %s until %s') % (
|
||||
leave.holiday_status_id.display_name, leave.holiday_status_id.validity_stop))
|
||||
|
||||
@api.model
|
||||
def create(self, values):
|
||||
|
||||
@@ -19,6 +19,7 @@ class TestLeavesRights(TestHrHolidaysBase):
|
||||
'name': 'Unlimited',
|
||||
'validation_type': 'hr',
|
||||
'allocation_type': 'no',
|
||||
'validity_start': False,
|
||||
})
|
||||
self.rd_dept.manager_id = False
|
||||
self.hr_dept.manager_id = False
|
||||
|
||||
@@ -20,12 +20,14 @@ class TestAccrualAllocations(TestHrHolidaysBase):
|
||||
self.accrual_type = LeaveType.create({
|
||||
'name': 'accrual',
|
||||
'allocation_type': 'fixed',
|
||||
'validity_start': False,
|
||||
})
|
||||
|
||||
self.unpaid_type = LeaveType.create({
|
||||
'name': 'unpaid',
|
||||
'allocation_type': 'no',
|
||||
'unpaid': True,
|
||||
'validity_start': False,
|
||||
})
|
||||
|
||||
self.set_employee_create_date(self.employee_emp_id, '2010-02-03 00:00:00')
|
||||
|
||||
@@ -29,11 +29,13 @@ class TestHolidaysFlow(TestHrHolidaysBase):
|
||||
'name': 'NotLimitedHR',
|
||||
'allocation_type': 'no',
|
||||
'validation_type': 'hr',
|
||||
'validity_start': False,
|
||||
})
|
||||
self.holidays_status_manager = HolidayStatusManagerGroup.create({
|
||||
'name': 'NotLimitedManager',
|
||||
'allocation_type': 'no',
|
||||
'validation_type': 'manager',
|
||||
'validity_start': False,
|
||||
})
|
||||
|
||||
HolidaysEmployeeGroup = Requests.sudo(self.user_employee_id)
|
||||
@@ -95,13 +97,15 @@ class TestHolidaysFlow(TestHrHolidaysBase):
|
||||
HolidayStatusManagerGroup.create({
|
||||
'name': 'WithMeetingType',
|
||||
'allocation_type': 'no',
|
||||
'categ_id': self.env['calendar.event.type'].sudo(self.user_hrmanager_id).create({'name': 'NotLimitedMeetingType'}).id
|
||||
'categ_id': self.env['calendar.event.type'].sudo(self.user_hrmanager_id).create({'name': 'NotLimitedMeetingType'}).id,
|
||||
'validity_start': False,
|
||||
})
|
||||
|
||||
self.holidays_status_limited = HolidayStatusManagerGroup.create({
|
||||
'name': 'Limited',
|
||||
'allocation_type': 'fixed',
|
||||
'validation_type': 'both',
|
||||
'validity_start': False,
|
||||
})
|
||||
HolidaysEmployeeGroup = Requests.sudo(self.user_employee_id)
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ class TestHrLeaveType(TestHrHolidaysBase):
|
||||
'name': 'Legal Leaves',
|
||||
'time_type': 'leave',
|
||||
'allocation_type': 'no',
|
||||
'validity_start': False,
|
||||
})
|
||||
|
||||
leave_1 = self.env['hr.leave'].create({
|
||||
|
||||
@@ -32,11 +32,13 @@ class TestLeaveRequests(TestHrHolidaysBase):
|
||||
'name': 'NotLimitedHR',
|
||||
'allocation_type': 'no',
|
||||
'validation_type': 'hr',
|
||||
'validity_start': False,
|
||||
})
|
||||
self.holidays_type_2 = LeaveType.create({
|
||||
'name': 'Limited',
|
||||
'allocation_type': 'fixed',
|
||||
'validation_type': 'hr',
|
||||
'validity_start': False,
|
||||
})
|
||||
self.holidays_type_3 = LeaveType.create({
|
||||
'name': 'TimeNotLimited',
|
||||
|
||||
@@ -46,6 +46,7 @@ class TestTimesheetHolidays(TestTimesheet):
|
||||
'timesheet_generate': True,
|
||||
'timesheet_project_id': self.internal_project.id,
|
||||
'timesheet_task_id': self.internal_task_leaves.id,
|
||||
'validity_start': False,
|
||||
})
|
||||
self.hr_leave_type_no_ts = self.env['hr.leave.type'].create({
|
||||
'name': 'Leave Type without timesheet generation',
|
||||
@@ -53,6 +54,7 @@ class TestTimesheetHolidays(TestTimesheet):
|
||||
'timesheet_generate': False,
|
||||
'timesheet_project_id': False,
|
||||
'timesheet_task_id': False,
|
||||
'validity_start': False,
|
||||
})
|
||||
|
||||
# HR Officer allocates some leaves to the employee 1
|
||||
|
||||
Reference in New Issue
Block a user