[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.
This commit is contained in:
Thibault Delavallée
2019-04-23 10:53:33 +00:00
parent 924a6d2a8a
commit bea9662632
7 changed files with 52 additions and 60 deletions
+5 -37
View File
@@ -18,60 +18,28 @@
<field name="image" eval="obj(ref('base.partner_admin')).image" model="res.partner"/>
</record>
<record id="activity_type_setup_it_materials" model="mail.activity.type">
<field name="name">Setup IT Materials</field>
<field name="res_model_id" ref="hr.model_hr_employee"/>
</record>
<record id="activity_type_setup_it_materials" model="mail.activity.type">
<field name="name">Setup IT Materials</field>
<field name="res_model_id" ref="hr.model_hr_employee"/>
</record>
<record id="activity_type_plan_training" model="mail.activity.type">
<field name="name">Plan Training</field>
<field name="res_model_id" ref="hr.model_hr_employee"/>
</record>
<record id="activity_type_training" model="mail.activity.type">
<field name="name">Training</field>
<field name="res_model_id" ref="hr.model_hr_employee"/>
<field name="delay_unit">weeks</field>
<field name="delay_count">1</field>
</record>
<record id="activity_type_compute_out_delais" model="mail.activity.type">
<field name="name">Compute Out Delais</field>
<field name="res_model_id" ref="hr.model_hr_employee"/>
</record>
<record id="activity_type_take_back_hr_materials" model="mail.activity.type">
<field name="name">Take Back HR Materials</field>
<field name="res_model_id" ref="hr.model_hr_employee"/>
</record>
<record id="onboarding_setup_it_materials" model="hr.plan.activity.type">
<field name="activity_type_id" ref="hr.activity_type_setup_it_materials"/>
<field name="summary">Setup IT Materials</field>
<field name="responsible">manager</field>
</record>
<record id="onboarding_plan_training" model="hr.plan.activity.type">
<field name="activity_type_id" ref="hr.activity_type_plan_training"/>
<field name="summary">Plan Training</field>
<field name="responsible">manager</field>
</record>
<record id="onboarding_training" model="hr.plan.activity.type">
<field name="activity_type_id" ref="hr.activity_type_training"/>
<field name="summary">Training</field>
<field name="responsible">employee</field>
</record>
<record id="offboarding_setup_compute_out_delais" model="hr.plan.activity.type">
<field name="activity_type_id" ref="hr.activity_type_compute_out_delais"/>
<field name="summary">Compute Out Delais</field>
<field name="responsible">manager</field>
</record>
<record id="offboarding_take_back_hr_materials" model="hr.plan.activity.type">
<field name="activity_type_id" ref="hr.activity_type_take_back_hr_materials"/>
<field name="summary">Take Back HR Materials</field>
<field name="responsible">manager</field>
</record>
+12 -4
View File
@@ -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
+3 -2
View File
@@ -76,7 +76,8 @@
<group string="Activities">
<field name="plan_activity_type_ids" nolabel="1">
<tree editable="bottom">
<field name="name"/>
<field name="activity_type_id"/>
<field name="summary"/>
<field name="responsible"/>
<field name="responsible_id" attrs="{'readonly': [('responsible', '!=', 'other')]}"/>
</tree>
@@ -94,7 +95,7 @@
<form string="Planning">
<sheet>
<group>
<field name="name"/>
<field name="summary"/>
<field name="activity_type_id"/>
<field name="responsible"/>
<field name="responsible_id" attrs="{'invisible': [('responsible', '!=', 'other')]}"/>
+12 -5
View File
@@ -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,
})
@@ -9,6 +9,7 @@
<sheet>
<group>
<field name="plan_id"/>
<field name="employee_id" invisible="1"/>
<field name="departure_reason"/>
<field name="departure_description"/>
</group>
+17 -11
View File
@@ -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")],
+2 -1
View File
@@ -9,10 +9,11 @@
<sheet>
<group>
<field name="plan_id"/>
<field name="employee_id" invisible="1"/>
</group>
</sheet>
<footer>
<button name="launch" string="Launch Plan" type="object" class="oe_highlight" groups="hr.group_hr_manager"/>
<button name="action_launch" string="Launch Plan" type="object" class="oe_highlight" groups="hr.group_hr_manager"/>
<button string="Cancel" class="btn-secondary" special="cancel"/>
</footer>
</form>