From 5c555995ee032a3c4930e49e814b3a033805f0cb Mon Sep 17 00:00:00 2001 From: Raouf Date: Tue, 17 May 2022 16:48:08 +0000 Subject: [PATCH] [IMP] project: prevent sending of emails when duplicating project or task After this commit: - When duplicating project or task, assignment notifications and emails on stages are not sent task-2849291 Part-of: odoo/odoo#91174 --- addons/project/models/project.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/addons/project/models/project.py b/addons/project/models/project.py index dbe8a85b53d..b1f43282285 100644 --- a/addons/project/models/project.py +++ b/addons/project/models/project.py @@ -610,7 +610,8 @@ class Project(models.Model): default = {} if not default.get('name'): default['name'] = _("%s (copy)") % (self.name) - project = super(Project, self).copy(default) + self_with_mail_context = self.with_context(mail_auto_subscribe_no_notify=True, mail_create_nosubscribe=True) + project = super(Project, self_with_mail_context).copy(default) for follower in self.message_follower_ids: project.message_subscribe(partner_ids=follower.partner_id.ids, subtype_ids=follower.subtype_ids.ids) if 'tasks' not in default: @@ -1726,7 +1727,8 @@ class Task(models.Model): default['recurrence_id'] = self.recurrence_id.copy().id if self.allow_subtasks: default['child_ids'] = [child.copy({'name': child.name} if has_default_name else None).id for child in self.child_ids] - task_copy = super(Task, self).copy(default) + self_with_mail_context = self.with_context(mail_auto_subscribe_no_notify=True, mail_create_nosubscribe=True) + task_copy = super(Task, self_with_mail_context).copy(default) if self.allow_task_dependencies: task_mapping = self.env.context.get('task_mapping') task_mapping[self.id] = task_copy.id @@ -2207,6 +2209,8 @@ class Task(models.Model): @api.model def _task_message_auto_subscribe_notify(self, users_per_task): + if self.env.context.get('mail_auto_subscribe_no_notify'): + return # Utility method to send assignation notification upon writing/creation. template_id = self.env['ir.model.data']._xmlid_to_res_id('project.project_message_user_assigned', raise_if_not_found=False) if not template_id: