From d5c16cdadfc2036e889f7f65226b0582c59e7fe1 Mon Sep 17 00:00:00 2001 From: Nicolas Martinelli Date: Mon, 24 Sep 2018 12:28:49 +0000 Subject: [PATCH] [FIX] project: copy project - Create a project - Create some tasks with followers - Create an outgoing mail server with active = False - Copy that project When copied, the project tries to send emails to followers using the inactive mail server. This leads to a traceback. The addition of the context key dates back to 2009 with 853789d0aaea956. The purpose was to copy all tasks, including the archived ones. We keep this behavior, but without propagating the `active_test` during the copy of the tasks. opw-1887354 closes odoo/odoo#27192 --- addons/project/models/project.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/addons/project/models/project.py b/addons/project/models/project.py index 89fc9d5741c..3f1035dd06a 100644 --- a/addons/project/models/project.py +++ b/addons/project/models/project.py @@ -228,7 +228,9 @@ class Project(models.Model): def map_tasks(self, new_project_id): """ copy and map tasks from old to new project """ tasks = self.env['project.task'] - for task in self.tasks: + # We want to copy archived task, but do not propagate an active_test context key + task_ids = self.env['project.task'].with_context(active_test=False).search([('project_id', '=', self.id)]).ids + for task in self.env['project.task'].browse(task_ids): # preserve task name and stage, normally altered during copy defaults = {'stage_id': task.stage_id.id, 'name': task.name} @@ -239,7 +241,6 @@ class Project(models.Model): def copy(self, default=None): if default is None: default = {} - self = self.with_context(active_test=False) if not default.get('name'): default['name'] = _("%s (copy)") % (self.name) project = super(Project, self).copy(default)