From 5f98b6acdb0bf9f556da62889c911d40179cd0c8 Mon Sep 17 00:00:00 2001 From: Kevin Baptiste Date: Fri, 26 Feb 2021 08:10:04 +0000 Subject: [PATCH] [IMP] hr: add a model for departure reasons The "Departure Reasons" where hardcoded and couldn't reflect all the valid departure reasons (like "End Of Fixed-Term Contract"). This commit introduces a new model `hr.departure.reason`. closes odoo/odoo#66905 Taskid: 2447056 Related: odoo/enterprise#16709 Related: odoo/upgrade#2211 Signed-off-by: Yannick Tivisse (yti) --- addons/hr/__manifest__.py | 1 + addons/hr/data/hr_data.xml | 15 ++++++++ addons/hr/models/__init__.py | 3 +- addons/hr/models/hr_departure_reason.py | 27 +++++++++++++++ addons/hr/models/hr_employee.py | 9 ++--- addons/hr/security/ir.model.access.csv | 1 + addons/hr/views/hr_departure_reason_views.xml | 34 +++++++++++++++++++ addons/hr/views/hr_employee_views.xml | 2 +- addons/hr/views/hr_views.xml | 7 ++++ addons/hr/wizard/hr_departure_wizard.py | 8 ++--- .../hr/wizard/hr_departure_wizard_views.xml | 2 +- 11 files changed, 94 insertions(+), 15 deletions(-) create mode 100644 addons/hr/models/hr_departure_reason.py create mode 100644 addons/hr/views/hr_departure_reason_views.xml diff --git a/addons/hr/__manifest__.py b/addons/hr/__manifest__.py index 2ccaa7557a0..601bfdf8ca2 100644 --- a/addons/hr/__manifest__.py +++ b/addons/hr/__manifest__.py @@ -26,6 +26,7 @@ 'security/ir.model.access.csv', 'wizard/hr_plan_wizard_views.xml', 'wizard/hr_departure_wizard_views.xml', + 'views/hr_departure_reason_views.xml', 'views/hr_job_views.xml', 'views/hr_plan_views.xml', 'views/hr_employee_category_views.xml', diff --git a/addons/hr/data/hr_data.xml b/addons/hr/data/hr_data.xml index b6810908c3d..805e9681994 100644 --- a/addons/hr/data/hr_data.xml +++ b/addons/hr/data/hr_data.xml @@ -74,5 +74,20 @@ True + + + 0 + Fired + + + + 1 + Resigned + + + + 2 + Retired + diff --git a/addons/hr/models/__init__.py b/addons/hr/models/__init__.py index 631717c89bf..1d9141cf1b8 100644 --- a/addons/hr/models/__init__.py +++ b/addons/hr/models/__init__.py @@ -1,11 +1,12 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. -from . import hr_employee_base +from . import hr_employee_base from . import hr_employee from . import hr_employee_category from . import hr_employee_public from . import hr_department +from . import hr_departure_reason from . import hr_job from . import hr_plan from . import hr_work_location diff --git a/addons/hr/models/hr_departure_reason.py b/addons/hr/models/hr_departure_reason.py new file mode 100644 index 00000000000..784695ae022 --- /dev/null +++ b/addons/hr/models/hr_departure_reason.py @@ -0,0 +1,27 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import api, fields, models, _ +from odoo.exceptions import UserError + + +class DepartureReason(models.Model): + _name = "hr.departure.reason" + _description = "Departure Reason" + _order = "sequence" + + sequence = fields.Integer("Sequence", default=10) + name = fields.Char(string="Reason", required=True, translate=True) + + def _get_default_departure_reasons(self): + return { + 'fired': self.env.ref('hr.departure_fired', False), + 'resigned': self.env.ref('hr.departure_resigned', False), + 'retired': self.env.ref('hr.departure_retired', False), + } + + @api.ondelete(at_uninstall=False) + def _unlink_except_default_departure_reasons(self): + ids = set(map(lambda a: a.id, self._get_default_departure_reasons().values())) + if set(self.ids) & ids: + raise UserError(_('Default departure reasons cannot be deleted.')) diff --git a/addons/hr/models/hr_employee.py b/addons/hr/models/hr_employee.py index ea7652c1d41..4e0ca54f726 100644 --- a/addons/hr/models/hr_employee.py +++ b/addons/hr/models/hr_employee.py @@ -106,11 +106,8 @@ class HrEmployeePrivate(models.Model): barcode = fields.Char(string="Badge ID", help="ID used for employee identification.", groups="hr.group_hr_user", copy=False) pin = fields.Char(string="PIN", groups="hr.group_hr_user", copy=False, help="PIN used to Check In/Out in the Kiosk Mode of the Attendance application (if enabled in Configuration) and to change the cashier in the Point of Sale application.") - departure_reason = fields.Selection([ - ('fired', 'Fired'), - ('resigned', 'Resigned'), - ('retired', 'Retired') - ], string="Departure Reason", groups="hr.group_hr_user", copy=False, tracking=True) + departure_reason_id = fields.Many2one("hr.departure.reason", string="Departure Reason", groups="hr.group_hr_user", + copy=False, tracking=True, ondelete='restrict') departure_description = fields.Text(string="Additional Information", groups="hr.group_hr_user", copy=False, tracking=True) departure_date = fields.Date(string="Departure Date", groups="hr.group_hr_user", copy=False, tracking=True) message_main_attachment_id = fields.Many2one(groups="hr.group_hr_user") @@ -273,7 +270,7 @@ class HrEmployeePrivate(models.Model): res = super(HrEmployeePrivate, self).toggle_active() unarchived_employees = self.filtered(lambda employee: employee.active) unarchived_employees.write({ - 'departure_reason': False, + 'departure_reason_id': False, 'departure_description': False, 'departure_date': False }) diff --git a/addons/hr/security/ir.model.access.csv b/addons/hr/security/ir.model.access.csv index 0367d605eca..91371e1a427 100644 --- a/addons/hr/security/ir.model.access.csv +++ b/addons/hr/security/ir.model.access.csv @@ -16,3 +16,4 @@ access_hr_plan_wizard,access.hr.plan.wizard,model_hr_plan_wizard,hr.group_hr_man access_hr_departure_wizard,access.hr.departure.wizard,model_hr_departure_wizard,hr.group_hr_user,1,1,1,0 access_hr_work_location_user,access_hr_work_location_user,model_hr_work_location,base.group_user,1,0,0,0 access_hr_work_location_manager,access_hr_work_location_manager,model_hr_work_location,group_hr_manager,1,1,1,1 +access_hr_departure_reason,access_hr_departure_reason_user,model_hr_departure_reason,group_hr_user,1,1,1,1 diff --git a/addons/hr/views/hr_departure_reason_views.xml b/addons/hr/views/hr_departure_reason_views.xml new file mode 100644 index 00000000000..f846b7c49cf --- /dev/null +++ b/addons/hr/views/hr_departure_reason_views.xml @@ -0,0 +1,34 @@ + + + + + hr.departure.reason + + + + + + + + + + hr.departure.reason + +
+ + + + + + +
+
+
+ + + Departure Reasons + hr.departure.reason + tree + +
+
diff --git a/addons/hr/views/hr_employee_views.xml b/addons/hr/views/hr_employee_views.xml index e26be2a9366..d8b1d12c705 100644 --- a/addons/hr/views/hr_employee_views.xml +++ b/addons/hr/views/hr_employee_views.xml @@ -111,7 +111,7 @@ - + diff --git a/addons/hr/views/hr_views.xml b/addons/hr/views/hr_views.xml index b6b40ad5990..e8e7e561fa5 100644 --- a/addons/hr/views/hr_views.xml +++ b/addons/hr/views/hr_views.xml @@ -97,6 +97,13 @@ sequence="5" groups="group_hr_user"/> + + - +