[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) <nim@odoo.com>
Signed-off-by: agr-odoo <agr-odoo@users.noreply.github.com>
This commit is contained in:
Andrea Grazioso (agr-odoo)
2020-10-26 08:08:19 +00:00
parent 1e9de61d81
commit b5d4e77b2c
@@ -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')),