From 0010be44bbf494b9b8f54eeef43ebfafa3d9694c Mon Sep 17 00:00:00 2001 From: Goffin Simon Date: Wed, 5 Jul 2017 09:58:34 +0200 Subject: [PATCH] [FIX] hr_timesheet: create a sub task When creating a sub task, the field default_parent_id is set in the context. When a sub task is created, a mail.compose.message was created with the same context. So the default parent_id set in the context (for a project.task record) was used to create the message and an error was raised in function get_record_data. opw:749435 --- addons/hr_timesheet/project_timesheet.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/addons/hr_timesheet/project_timesheet.py b/addons/hr_timesheet/project_timesheet.py index 400d5aedc6f..8a50f3c1ef4 100644 --- a/addons/hr_timesheet/project_timesheet.py +++ b/addons/hr_timesheet/project_timesheet.py @@ -67,3 +67,12 @@ class Task(models.Model): for task in self: if task.parent_id and task.parent_id.project_id and task.project_id and task.project_id != task.parent_id.project_id.subtask_project_id: raise UserError(_("You can't define a parent task if its project is not correctly configured. The sub-task's project of the parent task's project should be this task's project")) + + @api.model + def create(self, vals): + context = dict(self.env.context) + # Remove default_parent_id to avoid a confusion in get_record_data + if context.get('default_parent_id', False): + vals['parent_id'] = context.pop('default_parent_id', None) + task = super(Task, self.with_context(context)).create(vals) + return task