It was possible to assign a user that was not part of the same company as the employee's for an activity which is misleading. Make hr.plan and hr.plan.activity.type company dependent. closes odoo/odoo#77524 Related: odoo/upgrade#2879 Taskid: 2658773 Signed-off-by: Kevin Baptiste <kba@odoo.com>
69 lines
3.0 KiB
Python
69 lines
3.0 KiB
Python
# -*- 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 HrPlanActivityType(models.Model):
|
|
_name = 'hr.plan.activity.type'
|
|
_description = 'Plan activity type'
|
|
_rec_name = 'summary'
|
|
_check_company_auto = True
|
|
|
|
company_id = fields.Many2one('res.company', default=lambda self: self.env.company)
|
|
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', '=', False), ('res_model', '=', 'hr.employee')],
|
|
ondelete='restrict'
|
|
)
|
|
summary = fields.Char('Summary', compute="_compute_default_summary", store=True, readonly=False)
|
|
responsible = fields.Selection([
|
|
('coach', 'Coach'),
|
|
('manager', 'Manager'),
|
|
('employee', 'Employee'),
|
|
('other', 'Other')], default='employee', string='Responsible', required=True)
|
|
responsible_id = fields.Many2one('res.users', 'Name', help='Specific responsible of activity if not linked to the employee.', check_company=True)
|
|
note = fields.Html('Note')
|
|
|
|
|
|
@api.depends('activity_type_id')
|
|
def _compute_default_summary(self):
|
|
for plan_type in self:
|
|
if not plan_type.summary and plan_type.activity_type_id and plan_type.activity_type_id.summary:
|
|
plan_type.summary = plan_type.activity_type_id.summary
|
|
|
|
def get_responsible_id(self, employee):
|
|
if self.responsible == 'coach':
|
|
if not employee.coach_id:
|
|
raise UserError(_('Coach of employee %s is not set.', employee.name))
|
|
responsible = employee.coach_id.user_id
|
|
if not responsible:
|
|
raise UserError(_('User of coach of employee %s is not set.', employee.name))
|
|
elif self.responsible == 'manager':
|
|
if not employee.parent_id:
|
|
raise UserError(_('Manager of employee %s is not set.', employee.name))
|
|
responsible = employee.parent_id.user_id
|
|
if not responsible:
|
|
raise UserError(_('User of manager of employee %s is not set.', employee.name))
|
|
elif self.responsible == 'employee':
|
|
responsible = employee.user_id
|
|
if not responsible:
|
|
raise UserError(_('User linked to employee %s is required.', employee.name))
|
|
elif self.responsible == 'other':
|
|
responsible = self.responsible_id
|
|
if not responsible:
|
|
raise UserError(_('No specific user given on activity %s.', self.activity_type_id.name))
|
|
return responsible
|
|
|
|
|
|
class HrPlan(models.Model):
|
|
_name = 'hr.plan'
|
|
_description = 'plan'
|
|
|
|
name = fields.Char('Name', required=True)
|
|
company_id = fields.Many2one('res.company', default=lambda self: self.env.company)
|
|
plan_activity_type_ids = fields.Many2many('hr.plan.activity.type', string='Activities', domain="[('company_id', '=', company_id)]")
|
|
active = fields.Boolean(default=True)
|