Skip to content
Permalink
Browse files

[FIX] sale_timesheet: correct the context when viewing a contact's SO…

…'s tasks

When accessing a SO's tasks from Contacts (the partner_id's page), and
calling action_view_task, the active_id first corresponds to the contact's id.
Therefore, if a project.project exists with the contact's id, one can access
the SO's tasks, but otherwise, we get the error

Record does not exist or has been deleted.

(Records: [partner_id], User: ...)

Thus, if there is one corresponding project, we first update the context:
active_ids is set to project_id,
allowing access to the SO's corresponding project's tasks.
Note that the same thing is done lower:

eval_context.update({'active_id': task_projects.id})

which is too late to avoid trying to access the wrong record.

In the case where there are more than 1 corresponding projects (or if
there are no corresponding tasks), we don't have the issue.

OPW 2052559

closes #35792

Signed-off-by: Nans Lefebvre (len) <len@odoo.com>
  • Loading branch information...
fah-odoo committed Aug 19, 2019
1 parent 024d7eb commit f9f288cd476f3ba95887cf1c625d3285d0a051b1
Showing with 2 additions and 1 deletion.
  1. +2 −1 addons/sale_timesheet/models/sale_order.py
@@ -68,7 +68,8 @@ def action_view_task(self):

task_projects = self.tasks_ids.mapped('project_id')
if len(task_projects) == 1 and len(self.tasks_ids) > 1: # redirect to task of the project (with kanban stage, ...)
action = self.env.ref('project.act_project_project_2_project_task_all').read()[0]
action = self.with_context(active_id=task_projects.id).env.ref(
'project.act_project_project_2_project_task_all').read()[0]
if action.get('context'):
eval_context = self.env['ir.actions.actions']._get_eval_context()
eval_context.update({'active_id': task_projects.id})

0 comments on commit f9f288c

Please sign in to comment.
You can’t perform that action at this time.