From 32a8b4dce37c256acd562f898f6e70d5aed8109b Mon Sep 17 00:00:00 2001
From: Kevin Baptiste <kba@odoo.com>
Date: Fri, 7 Feb 2020 08:39:05 +0000
Subject: [PATCH] [IMP] crm: make unlink optional in merge_opportunity

closes odoo/odoo#44997

X-original-commit: a8094108a4e469f5bc4a3ba541ede7a61f28d522
Related: odoo/enterprise#8311
Signed-off-by: Yannick Tivisse (yti) <yti@odoo.com>
---
 addons/crm/models/crm_lead.py | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/addons/crm/models/crm_lead.py b/addons/crm/models/crm_lead.py
index fe665a5fc2ee..5ccbdce7feb0 100644
--- a/addons/crm/models/crm_lead.py
+++ b/addons/crm/models/crm_lead.py
@@ -812,7 +812,7 @@ class Lead(models.Model):
         self._merge_opportunity_history(opportunities)
         self._merge_opportunity_attachments(opportunities)
 
-    def merge_opportunity(self, user_id=False, team_id=False):
+    def merge_opportunity(self, user_id=False, team_id=False, auto_unlink=True):
         """ Merge opportunities in one. Different cases of merge:
                 - merge leads together = 1 new lead
                 - merge at least 1 opp with anything else (lead or opp) = 1 new opp
@@ -855,7 +855,8 @@ class Lead(models.Model):
 
         # delete tail opportunities
         # we use the SUPERUSER to avoid access rights issues because as the user had the rights to see the records it should be safe to do so
-        opportunities_tail.sudo().unlink()
+        if auto_unlink:
+            opportunities_tail.sudo().unlink()
 
         return opportunities_head
 
-- 
GitLab