From 3b43ddd21bfb8164cc9123393395b2916fcadd84 Mon Sep 17 00:00:00 2001
From: Nicolas Martinelli <nim@odoo.com>
Date: Tue, 7 Nov 2017 14:47:31 +0100
Subject: [PATCH] [FIX] crm: default user when copy

- Create a user A
- Create a lead, assign to A
- Deactivate user A
- Duplicate the lead

A notification email is sent to A (user assigned to the lead).

Since the user is archived, he should not receive any email since it
might contain sensitive information.

opw-778825
---
 addons/crm/models/crm_lead.py | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/addons/crm/models/crm_lead.py b/addons/crm/models/crm_lead.py
index 879350cf55d6..f23d5382b2f1 100644
--- a/addons/crm/models/crm_lead.py
+++ b/addons/crm/models/crm_lead.py
@@ -336,6 +336,9 @@ class Lead(FormatAddress, models.Model):
         # Set date_open to today if it is an opp
         default = default or {}
         default['date_open'] = fields.Datetime.now() if self.type == 'opportunity' else False
+        # Do not assign to an archived user
+        if not self.user_id.active:
+            default['user_id'] = False
         return super(Lead, self.with_context(context)).copy(default=default)
 
     @api.model
-- 
GitLab