diff options
| author | Nicolas Martinelli <nim@odoo.com> | 2019-06-18 15:36:09 +0000 |
|---|---|---|
| committer | Nicolas Martinelli <nim@odoo.com> | 2019-06-19 09:55:56 +0000 |
| commit | ba2c179c44af63ae1473e3c9ea3428fdddaf48b2 (patch) | |
| tree | 25960be4ca75226b211422152cd702ac7492044a | |
| parent | 84b89555c09395b16a3a9f349678a88573135f9a (diff) | |
[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>
| -rw-r--r-- | addons/hr_holidays/i18n/hr_holidays.pot | 30 | ||||
| -rw-r--r-- | addons/hr_holidays/models/hr_leave.py | 19 | ||||
| -rw-r--r-- | addons/hr_holidays/tests/test_access_rights.py | 1 | ||||
| -rw-r--r-- | addons/hr_holidays/tests/test_accrual_allocations.py | 2 | ||||
| -rw-r--r-- | addons/hr_holidays/tests/test_holidays_flow.py | 6 | ||||
| -rw-r--r-- | addons/hr_holidays/tests/test_hr_leave_type.py | 1 | ||||
| -rw-r--r-- | addons/hr_holidays/tests/test_leave_requests.py | 2 | ||||
| -rw-r--r-- | addons/project_timesheet_holidays/tests/test_timesheet_holidays.py | 2 |
8 files changed, 52 insertions, 11 deletions
diff --git a/addons/hr_holidays/i18n/hr_holidays.pot b/addons/hr_holidays/i18n/hr_holidays.pot index ba7cc0531f2..80ea6c69104 100644 --- a/addons/hr_holidays/i18n/hr_holidays.pot +++ b/addons/hr_holidays/i18n/hr_holidays.pot @@ -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,13 +2534,18 @@ 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" msgstr "" diff --git a/addons/hr_holidays/models/hr_leave.py b/addons/hr_holidays/models/hr_leave.py index 57d72ca3da4..4bf02afdc99 100644 --- a/addons/hr_holidays/models/hr_leave.py +++ b/addons/hr_holidays/models/hr_leave.py @@ -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): diff --git a/addons/hr_holidays/tests/test_access_rights.py b/addons/hr_holidays/tests/test_access_rights.py index ca651a69010..3f533749a6c 100644 --- a/addons/hr_holidays/tests/test_access_rights.py +++ b/addons/hr_holidays/tests/test_access_rights.py @@ -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 diff --git a/addons/hr_holidays/tests/test_accrual_allocations.py b/addons/hr_holidays/tests/test_accrual_allocations.py index c877643cc2e..270599fa26e 100644 --- a/addons/hr_holidays/tests/test_accrual_allocations.py +++ b/addons/hr_holidays/tests/test_accrual_allocations.py @@ -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') diff --git a/addons/hr_holidays/tests/test_holidays_flow.py b/addons/hr_holidays/tests/test_holidays_flow.py index 08e1be1b20d..488f2ee1079 100644 --- a/addons/hr_holidays/tests/test_holidays_flow.py +++ b/addons/hr_holidays/tests/test_holidays_flow.py @@ -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) diff --git a/addons/hr_holidays/tests/test_hr_leave_type.py b/addons/hr_holidays/tests/test_hr_leave_type.py index dfe1b77713d..e6d5a694c7e 100644 --- a/addons/hr_holidays/tests/test_hr_leave_type.py +++ b/addons/hr_holidays/tests/test_hr_leave_type.py @@ -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({ diff --git a/addons/hr_holidays/tests/test_leave_requests.py b/addons/hr_holidays/tests/test_leave_requests.py index 0126116f756..bbbeb23df10 100644 --- a/addons/hr_holidays/tests/test_leave_requests.py +++ b/addons/hr_holidays/tests/test_leave_requests.py @@ -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', diff --git a/addons/project_timesheet_holidays/tests/test_timesheet_holidays.py b/addons/project_timesheet_holidays/tests/test_timesheet_holidays.py index 06365153438..191fd15f9b7 100644 --- a/addons/project_timesheet_holidays/tests/test_timesheet_holidays.py +++ b/addons/project_timesheet_holidays/tests/test_timesheet_holidays.py @@ -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 |
