[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) <yti@odoo.com>
This commit is contained in:
committed by
Yannick Tivisse
parent
e426492142
commit
5f98b6acdb
@@ -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',
|
||||
|
||||
@@ -74,5 +74,20 @@
|
||||
<field name="value">True</field>
|
||||
</record>
|
||||
|
||||
<!-- Departure Reasons -->
|
||||
<record id="departure_fired" model="hr.departure.reason">
|
||||
<field name="sequence">0</field>
|
||||
<field name="name">Fired</field>
|
||||
</record>
|
||||
|
||||
<record id="departure_resigned" model="hr.departure.reason">
|
||||
<field name="sequence">1</field>
|
||||
<field name="name">Resigned</field>
|
||||
</record>
|
||||
|
||||
<record id="departure_retired" model="hr.departure.reason">
|
||||
<field name="sequence">2</field>
|
||||
<field name="name">Retired</field>
|
||||
</record>
|
||||
</data>
|
||||
</odoo>
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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.'))
|
||||
@@ -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
|
||||
})
|
||||
|
||||
@@ -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
|
||||
|
||||
|
@@ -0,0 +1,34 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
<data>
|
||||
<record id="hr_departure_reason_view_list" model="ir.ui.view">
|
||||
<field name="model">hr.departure.reason</field>
|
||||
<field name="arch" type="xml">
|
||||
<tree editable="bottom">
|
||||
<field name="sequence" widget="handle" />
|
||||
<field name="name" />
|
||||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="hr_departure_reason_view_form" model="ir.ui.view">
|
||||
<field name="model">hr.departure.reason</field>
|
||||
<field name="arch" type="xml">
|
||||
<form>
|
||||
<group>
|
||||
<group>
|
||||
<field name="sequence" />
|
||||
<field name="name" />
|
||||
</group>
|
||||
</group>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="hr_departure_reason_action" model="ir.actions.act_window">
|
||||
<field name="name">Departure Reasons</field>
|
||||
<field name="res_model">hr.departure.reason</field>
|
||||
<field name="view_mode">tree</field>
|
||||
</record>
|
||||
</data>
|
||||
</odoo>
|
||||
@@ -111,7 +111,7 @@
|
||||
<!-- is overridden in other hr related modules -->
|
||||
</group>
|
||||
<group name="departure" string="Departure" attrs="{'invisible': [('active', '=', True)]}">
|
||||
<field name="departure_reason"/>
|
||||
<field name="departure_reason_id" options="{'no_edit': True, 'no_create': True, 'no_open': True}"/>
|
||||
<field name="departure_description"/>
|
||||
<field name="departure_date"/>
|
||||
</group>
|
||||
|
||||
@@ -97,6 +97,13 @@
|
||||
sequence="5"
|
||||
groups="group_hr_user"/>
|
||||
|
||||
<menuitem
|
||||
id="menu_hr_departure_reason_tree"
|
||||
action="hr_departure_reason_action"
|
||||
parent="menu_human_resources_configuration"
|
||||
sequence="5"
|
||||
groups="group_hr_user"/>
|
||||
|
||||
<menuitem
|
||||
id="menu_config_plan"
|
||||
name="Activity Planning"
|
||||
|
||||
@@ -8,11 +8,7 @@ class HrDepartureWizard(models.TransientModel):
|
||||
_name = 'hr.departure.wizard'
|
||||
_description = 'Departure Wizard'
|
||||
|
||||
departure_reason = fields.Selection([
|
||||
('fired', 'Fired'),
|
||||
('resigned', 'Resigned'),
|
||||
('retired', 'Retired')
|
||||
], string="Departure Reason", default="fired")
|
||||
departure_reason_id = fields.Many2one("hr.departure.reason", default=lambda self: self.env['hr.departure.reason'].search([], limit=1))
|
||||
departure_description = fields.Text(string="Additional Information")
|
||||
departure_date = fields.Date(string="Departure Date", required=True, default=fields.Date.today)
|
||||
employee_id = fields.Many2one(
|
||||
@@ -23,7 +19,7 @@ class HrDepartureWizard(models.TransientModel):
|
||||
|
||||
def action_register_departure(self):
|
||||
employee = self.employee_id
|
||||
employee.departure_reason = self.departure_reason
|
||||
employee.departure_reason_id = self.departure_reason_id
|
||||
employee.departure_description = self.departure_description
|
||||
employee.departure_date = self.departure_date
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
<sheet>
|
||||
<group id="info" string="Departure Info">
|
||||
<field name="employee_id" invisible="1"/>
|
||||
<field name="departure_reason"/>
|
||||
<field name="departure_reason_id" options="{'no_edit': True, 'no_create': True, 'no_open': True}"/>
|
||||
<field name="departure_description"/>
|
||||
<field name="archive_private_address"/>
|
||||
</group>
|
||||
|
||||
Reference in New Issue
Block a user