[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 853789d0aa.
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
This commit is contained in:
Nicolas Martinelli
2018-09-24 13:22:42 +00:00
parent 66c125ae96
commit d5c16cdadf
+3 -2
View File
@@ -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)