[FIX] hr: Fix departure wizard activity generation

Purpose
=======

If the fired employee has no access to the hr.employee model,
the departure wizard will lead to a traceback, as we try to
create an activity on a model for which the user won't be able
to resolve it.

Create an activity on the related partner instead.
This commit is contained in:
Yannick Tivisse
2019-07-12 13:01:36 +02:00
parent 883c96b781
commit 1680b171a3
+5 -2
View File
@@ -30,10 +30,13 @@ class HrDepartureWizard(models.TransientModel):
employee.departure_reason = self.departure_reason
employee.departure_description = self.departure_description
if not employee.user_id.partner_id:
return
for activity_type in self.plan_id.plan_activity_type_ids:
self.env['mail.activity'].create({
'res_id': employee.id,
'res_model_id': self.env['ir.model']._get('hr.employee').id,
'res_id': employee.user_id.partner_id.id,
'res_model_id': self.env['ir.model']._get('res.partner').id,
'activity_type_id': activity_type.activity_type_id.id,
'summary': activity_type.summary,
'user_id': activity_type.get_responsible_id(employee).id,