From 22e33a7a3d57e1fac63585703ff4cd3a39d4b3e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Thu, 20 Sep 2018 09:32:38 +0200 Subject: [PATCH] [IMP] crm: restore default stage probably when restoring leads Purpose of this commit is to avoid having restored leads and opportunities having always 0 probability even if the stage has an high probably than that. This commit is linked to task ID 1880051 and PR #26977. --- addons/crm/models/crm_lead.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/addons/crm/models/crm_lead.py b/addons/crm/models/crm_lead.py index fe96108292c..b6829a25708 100644 --- a/addons/crm/models/crm_lead.py +++ b/addons/crm/models/crm_lead.py @@ -451,6 +451,14 @@ class Lead(models.Model): 'context': {'default_type': 'opportunity'} } + def toggle_active(self): + """ When re-activating leads and opportunities set their probability + to the default stage one. """ + res = super(Lead, self).toggle_active() + for lead in self.filtered(lambda lead: lead.active and lead.stage_id.probability): + lead.probability = lead.stage_id.probability + return res + # ---------------------------------------- # Business Methods # ----------------------------------------