From ebbece6d55b33b41b39412cb189d19296a2a7e41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Fri, 11 Dec 2020 14:25:26 +0000 Subject: [PATCH] [IMP] crm: synchronize teams use_lead and alias with setting PURPOSE Remove the alias setting option because it is a weird and hackish way to proceed. We would prefer users to configure their alias through sales teams. Improve alias configuration on teams. SPECIFICATIONS When changing "use leads" from CRM settings automatically regenerate apply this option to all sales teams using opportunities. When de-activating it no team should have this option activated as menus and options are hidden. When activating it we consider that all teams should be upgraded by default. LINKS Task ID-2414079 COM PR odoo/odoo#63160 UPG PR odoo/upgrade#2017 --- addons/crm/models/res_config_settings.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/addons/crm/models/res_config_settings.py b/addons/crm/models/res_config_settings.py index bccf20a322e..994c37bce9b 100644 --- a/addons/crm/models/res_config_settings.py +++ b/addons/crm/models/res_config_settings.py @@ -59,9 +59,14 @@ class ResConfigSettings(models.TransientModel): setting.predictive_lead_scoring_start_date_str = fields.Date.to_string(setting.predictive_lead_scoring_start_date) def set_values(self): + group_lead_before = self.env.ref('crm.group_use_lead') in self.env.user.groups_id super(ResConfigSettings, self).set_values() - for team in self.env['crm.team'].search([]): - team.alias_id.write(team._alias_get_creation_values()) + group_lead_after = self.env.ref('crm.group_use_lead') in self.env.user.groups_id + if group_lead_before != group_lead_after: + teams = self.env['crm.team'].search([]) + teams.filtered('use_opportunities').use_leads = group_lead_after + for team in teams: + team.alias_id.write(team._alias_get_creation_values()) # ACTIONS def action_reset_lead_probabilities(self):