From bea9662632274ea7af669a7e73d66cfed54a2c9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Tue, 15 Jan 2019 12:46:14 +0000 Subject: [PATCH] [REF] hr: allow to customize activity types in plan Purpose of this merge is to avoid having to define custom activity types for each step of HR onboarding plan. This is done by adding a summary field on hr activities, allowing to use default Todo activity type and customize directly the summary itself. Using custom activity types is still possible. Here we allow to avoid noise and having too much activity types defined as most of those activities can be simulated using the default Todo. People can still define and use their own activity types if necessary and required in their daily workflow. Commit linked to task ID 1923387 and PR #30235. --- addons/hr/data/hr_data.xml | 42 +++---------------- addons/hr/models/hr_plan.py | 16 +++++-- addons/hr/views/hr_views.xml | 5 ++- addons/hr/wizard/hr_departure_wizard.py | 17 +++++--- .../hr/wizard/hr_departure_wizard_views.xml | 1 + addons/hr/wizard/hr_plan_wizard.py | 28 ++++++++----- addons/hr/wizard/hr_plan_wizard_views.xml | 3 +- 7 files changed, 52 insertions(+), 60 deletions(-) diff --git a/addons/hr/data/hr_data.xml b/addons/hr/data/hr_data.xml index 7436e422be6..869a74a8350 100644 --- a/addons/hr/data/hr_data.xml +++ b/addons/hr/data/hr_data.xml @@ -18,60 +18,28 @@ - - Setup IT Materials - - - - - Setup IT Materials - - - - - Plan Training - - - - - Training - - weeks - 1 - - - - Compute Out Delais - - - - - Take Back HR Materials - - - - + Setup IT Materials manager - + Plan Training manager - + Training employee - + Compute Out Delais manager - + Take Back HR Materials manager diff --git a/addons/hr/models/hr_plan.py b/addons/hr/models/hr_plan.py index fee13675130..fb999597398 100644 --- a/addons/hr/models/hr_plan.py +++ b/addons/hr/models/hr_plan.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. -from odoo import fields, models, _ +from odoo import api, fields, models, _ from odoo.exceptions import UserError @@ -9,9 +9,12 @@ class PlanActivityType(models.Model): _name = 'hr.plan.activity.type' _description = 'Plan activity type' - activity_type_id = fields.Many2one('mail.activity.type', 'Activity Type', - domain=lambda self: [('res_model_id', '=', self.env['ir.model']._get('hr.employee').id)]) - name = fields.Char(related='activity_type_id.name') + activity_type_id = fields.Many2one( + 'mail.activity.type', 'Activity Type', + default=lambda self: self.env.ref('mail.mail_activity_data_todo'), + domain=lambda self: ['|', ('res_model_id', '=', False), ('res_model_id', '=', self.env['ir.model']._get('hr.employee').id)] + ) + summary = fields.Char('Summary') responsible = fields.Selection([ ('coach', 'Coach'), ('manager', 'Manager'), @@ -19,6 +22,11 @@ class PlanActivityType(models.Model): ('other', 'Other')], default='employee', string='Responsible') responsible_id = fields.Many2one('res.users', 'Responsible Person') + @api.onchange('activity_type_id') + def _onchange_activity_type_id(self): + if self.activity_type_id and self.activity_type_id.summary and not self.summary: + self.summary = self.activity_type_id.summary + def get_responsible_id(self, employee_id): if self.responsible == 'coach': self.responsible_id = employee_id.coach_id.user_id diff --git a/addons/hr/views/hr_views.xml b/addons/hr/views/hr_views.xml index a175fb96811..3ba86ab5bba 100644 --- a/addons/hr/views/hr_views.xml +++ b/addons/hr/views/hr_views.xml @@ -76,7 +76,8 @@ - + + @@ -94,7 +95,7 @@
- + diff --git a/addons/hr/wizard/hr_departure_wizard.py b/addons/hr/wizard/hr_departure_wizard.py index 9efa96351c3..70405c5b04d 100644 --- a/addons/hr/wizard/hr_departure_wizard.py +++ b/addons/hr/wizard/hr_departure_wizard.py @@ -1,14 +1,21 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. -from odoo import fields, models, _ -from odoo.exceptions import UserError +from odoo import api, fields, models class HrDepartureWizard(models.TransientModel): _name = 'hr.departure.wizard' _description = 'Departure Wizard' + @api.model + def default_get(self, fields): + res = super(HrDepartureWizard, self).default_get(fields) + if (not fields or 'employee_id' in fields) and 'employee_id' not in res: + if self.env.context.get('active_id'): + res['employee_id'] = self.env.context['active_id'] + return res + departure_reason = fields.Selection([ ('fired', 'Fired'), ('resigned', 'Resigned'), @@ -16,11 +23,10 @@ class HrDepartureWizard(models.TransientModel): ], string="Departure Reason", default="fired") departure_description = fields.Text(string="Additional Information") plan_id = fields.Many2one('hr.plan', default=lambda self: self.env['hr.plan'].search([], limit=1)) + employee_id = fields.Many2one('hr.employee', string='Employee', required=True) def action_register_departure(self): - active_id = self.env.context.get('active_id') - - employee = self.env['hr.employee'].browse(active_id) + employee = self.employee_id employee.departure_reason = self.departure_reason employee.departure_description = self.departure_description @@ -29,5 +35,6 @@ class HrDepartureWizard(models.TransientModel): 'res_id': employee.id, 'res_model_id': self.env['ir.model']._get('hr.employee').id, 'activity_type_id': activity_type.activity_type_id.id, + 'summary': activity_type.summary, 'user_id': activity_type.get_responsible_id(employee).id, }) diff --git a/addons/hr/wizard/hr_departure_wizard_views.xml b/addons/hr/wizard/hr_departure_wizard_views.xml index 4e0ca36abfe..58679ba52cd 100644 --- a/addons/hr/wizard/hr_departure_wizard_views.xml +++ b/addons/hr/wizard/hr_departure_wizard_views.xml @@ -9,6 +9,7 @@ + diff --git a/addons/hr/wizard/hr_plan_wizard.py b/addons/hr/wizard/hr_plan_wizard.py index b08428829ee..654484f431c 100644 --- a/addons/hr/wizard/hr_plan_wizard.py +++ b/addons/hr/wizard/hr_plan_wizard.py @@ -1,34 +1,40 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. -from odoo import fields, models, _ -from odoo.exceptions import UserError +from odoo import api, fields, models class HrPlanWizard(models.TransientModel): _name = 'hr.plan.wizard' _description = 'Plan Wizard' + @api.model + def default_get(self, fields): + res = super(HrPlanWizard, self).default_get(fields) + if (not fields or 'employee_id' in fields) and 'employee_id' not in res: + if self.env.context.get('active_id'): + res['employee_id'] = self.env.context['active_id'] + return res + plan_id = fields.Many2one('hr.plan', default=lambda self: self.env['hr.plan'].search([], limit=1)) + employee_id = fields.Many2one('hr.employee', string='Employee', required=True) - def launch(self): - active_id = self.env.context.get('active_id') - - rec = self.env['hr.employee'].browse(active_id) - + @api.multi + def action_launch(self): for activity_type in self.plan_id.plan_activity_type_ids: self.env['mail.activity'].create({ - 'res_id': rec.id, + 'res_id': self.employee_id.id, 'res_model_id': self.env['ir.model']._get('hr.employee').id, + 'summary': activity_type.summary, 'activity_type_id': activity_type.activity_type_id.id, - 'user_id': activity_type.get_responsible_id(rec).id, + 'user_id': activity_type.get_responsible_id(self.employee_id).id, }) return { 'type': 'ir.actions.act_window', 'res_model': 'hr.employee', - 'res_id': active_id, - 'name': rec.display_name, + 'res_id': self.employee_id.id, + 'name': self.employee_id.display_name, 'view_type': 'form', 'view_mode': 'form', 'views': [(False, "form")], diff --git a/addons/hr/wizard/hr_plan_wizard_views.xml b/addons/hr/wizard/hr_plan_wizard_views.xml index b6829e17ea3..592759bb631 100644 --- a/addons/hr/wizard/hr_plan_wizard_views.xml +++ b/addons/hr/wizard/hr_plan_wizard_views.xml @@ -9,10 +9,11 @@ +