From b5d4e77b2c59ab170ec492d6a9f69ce1c4cfd733 Mon Sep 17 00:00:00 2001 From: "Andrea Grazioso (agr-odoo)" Date: Mon, 12 Oct 2020 12:49:44 +0000 Subject: [PATCH] [FIX] sale_timesheet: fix task creation when no tasks Create a sale order with a service configured with - Service Invoicing Policy: Timesheets on tasks - Service Tracking: Create a new project but no task Save and confirm. Access the project and the tasks via smart button. Create a new task. The task will not be saved under the current project because there is no data reference in context. opw-2355547 closes odoo/odoo#60692 X-original-commit: 51ce1d6ca479b4d851eacef70212bf890588e1c7 Signed-off-by: Nicolas Martinelli (nim) Signed-off-by: agr-odoo --- addons/sale_timesheet/models/project_overview.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/addons/sale_timesheet/models/project_overview.py b/addons/sale_timesheet/models/project_overview.py index c752f67ea2a..d3b58dd3097 100644 --- a/addons/sale_timesheet/models/project_overview.py +++ b/addons/sale_timesheet/models/project_overview.py @@ -446,12 +446,14 @@ class Project(models.Model): late_tasks_domain = [('project_id', 'in', self.ids), ('date_deadline', '<', fields.Date.to_string(fields.Date.today())), ('date_end', '=', False)] overtime_tasks_domain = [('project_id', 'in', self.ids), ('overtime', '>', 0), ('planned_hours', '>', 0)] - # filter out all the projects that have no tasks - task_projects_ids = self.env['project.task'].read_group([('project_id', 'in', self.ids)], ['project_id'], ['project_id']) - task_projects_ids = [p['project_id'][0] for p in task_projects_ids] + if len(self) == 1: + tasks_context = {**tasks_context, 'default_project_id': self.id} + elif len(self): + task_projects_ids = self.env['project.task'].read_group([('project_id', 'in', self.ids)], ['project_id'], ['project_id']) + task_projects_ids = [p['project_id'][0] for p in task_projects_ids] + if len(task_projects_ids) == 1: + tasks_context = {**tasks_context, 'default_project_id': task_projects_ids[0]} - if len(task_projects_ids) == 1: - tasks_context = {**tasks_context, 'default_project_id': task_projects_ids[0]} stat_buttons.append({ 'name': _('Tasks'), 'count': sum(self.mapped('task_count')),