summaryrefslogtreecommitdiff
path: root/addons/hr/wizard
diff options
context:
space:
mode:
authorThibault Delavallée <tde@odoo.com>2019-01-15 12:46:14 +0000
committerThibault Delavallée <tde@odoo.com>2019-04-23 10:53:33 +0000
commitbea9662632274ea7af669a7e73d66cfed54a2c9f (patch)
tree87e11f1aeb81bf0aa840c979df06d2381ca76b96 /addons/hr/wizard
parent924a6d2a8ac535c634e58449b96c3254bb108e17 (diff)
[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.
Diffstat (limited to 'addons/hr/wizard')
-rw-r--r--addons/hr/wizard/hr_departure_wizard.py17
-rw-r--r--addons/hr/wizard/hr_departure_wizard_views.xml1
-rw-r--r--addons/hr/wizard/hr_plan_wizard.py28
-rw-r--r--addons/hr/wizard/hr_plan_wizard_views.xml3
4 files changed, 32 insertions, 17 deletions
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 @@
<sheet>
<group>
<field name="plan_id"/>
+ <field name="employee_id" invisible="1"/>
<field name="departure_reason"/>
<field name="departure_description"/>
</group>
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'
- plan_id = fields.Many2one('hr.plan', default=lambda self: self.env['hr.plan'].search([], limit=1))
-
- def launch(self):
- active_id = self.env.context.get('active_id')
+ @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
- rec = self.env['hr.employee'].browse(active_id)
+ 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)
+ @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 @@
<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>