We convert the custom plan implementation to use the generic one. As the generic one can define plans for multiple model. We use the check dedicated_to_res_model == 'hr.employee' to activate the specific feature for hr.employee. Indeed, that field contains the model name when the plan is applicable only for one model. We also remove the 'launch plan' button as we can now launch a plan directly from the activities button in the chatter. Technical notes: For the activity schedule wizard, we add the support for active_ids and active_model as default values for res_ids and res_model because it is used as link in the chatter to launch the wizard and we want to avoid a big migration by keeping the link identical (and there are probably no simple solution to keep the same behavior). HR CONTRACT Before the first contract date of the first selected element was chosen to determine the planned due date if all first contract date were different otherwise the minimum was chosen. So if the selection included 2 different date among 3, the minimum was chosen but the first if the 3 were different. With this change, the minimum is always used to determine the default planned due date. Task-3390865 Part-of: odoo/odoo#137969
50 lines
2.3 KiB
Python
50 lines
2.3 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 ValidationError
|
|
|
|
|
|
class MailActivityPLanTemplate(models.Model):
|
|
_inherit = 'mail.activity.plan.template'
|
|
|
|
responsible_type = fields.Selection(selection_add=[
|
|
('coach', 'Coach'),
|
|
('manager', 'Manager'),
|
|
('employee', 'Employee'),
|
|
], ondelete={'coach': 'cascade', 'manager': 'cascade', 'employee': 'cascade'})
|
|
|
|
@api.constrains('plan_id', 'responsible_type')
|
|
def _check_responsible_hr(self):
|
|
""" Ensure that hr types are used only on employee model """
|
|
for template in self.filtered(lambda tpl: tpl.plan_id.res_model != 'hr.employee'):
|
|
if template.responsible_type in {'coach', 'manager', 'employee'}:
|
|
raise ValidationError(_('Those responsible types are limited to Employee plans.'))
|
|
|
|
def _determine_responsible(self, on_demand_responsible, employee):
|
|
if self.plan_id.res_model != 'hr.employee' or self.responsible_type not in {'coach', 'manager', 'employee'}:
|
|
return super()._determine_responsible(on_demand_responsible, employee)
|
|
error = False
|
|
responsible = False
|
|
if self.responsible_type == 'coach':
|
|
if not employee.coach_id:
|
|
error = _('Coach of employee %s is not set.', employee.name)
|
|
responsible = employee.coach_id.user_id
|
|
if employee.coach_id and not responsible:
|
|
error = _("The user of %s's coach is not set.", employee.name)
|
|
elif self.responsible_type == 'manager':
|
|
if not employee.parent_id:
|
|
error = _('Manager of employee %s is not set.', employee.name)
|
|
responsible = employee.parent_id.user_id
|
|
if employee.parent_id and not responsible:
|
|
error = _("The manager of %s should be linked to a user.", employee.name)
|
|
elif self.responsible_type == 'employee':
|
|
responsible = employee.user_id
|
|
if not responsible:
|
|
error = _('The employee %s should be linked to a user.', employee.name)
|
|
if error or responsible:
|
|
return {
|
|
'responsible': responsible,
|
|
'error': error,
|
|
}
|