From 1ee68e61191fe56743fb007d33be2e69cfaf9ac0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Thu, 10 Dec 2020 12:40:24 +0000 Subject: [PATCH 1/4] [REF] crm: remove global lead alias MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. RATIONALE "​Incoming Emails" option has many flaws * it creates collision when you try to set an alias that is already used and it is not easy to find them back; * it has no default value (no sales team, no type, ...) and works through the 'owner' field. This is set with the admin on activation of the feature which is not correct. The admin is potentially not a salesperson. If you set the field to blank, you get leads without team and without assigned responsible. * this alias is not team-bound which thus asks the question: in which team should the lead ever go? To the first team? Why? All this make it seem way healthier to handle this through the Sales Team. => By default, we'll already have one working with an alias. If users really want a global lead alias it can be setup manually through alias menu in configuration. Shortcut and default alias in crm are removed but feature is still doable if requested. SPECIFICATIONS Remove the s "Incoming emails" setting that allows to setup a global alias for leads / opportunities with a default value being 'contact'. Also remove related alias data as it has no use anymore. LINKS Task ID-2414079 Sort of follow-up of Task ID-2373095. COM PR odoo/odoo#63160 UPG PR odoo/upgrade#2017 --- addons/crm/__manifest__.py | 2 +- addons/crm/data/mail_data.xml | 8 ---- addons/crm/models/res_config_settings.py | 47 ------------------- .../crm/views/res_config_settings_views.xml | 26 ---------- 4 files changed, 1 insertion(+), 82 deletions(-) diff --git a/addons/crm/__manifest__.py b/addons/crm/__manifest__.py index e474ef3e83e..d74210125f3 100644 --- a/addons/crm/__manifest__.py +++ b/addons/crm/__manifest__.py @@ -3,7 +3,7 @@ { 'name': 'CRM', - 'version': '1.3', + 'version': '1.4', 'category': 'Sales/CRM', 'sequence': 15, 'summary': 'Track leads and close opportunities', diff --git a/addons/crm/data/mail_data.xml b/addons/crm/data/mail_data.xml index 9ad6c946d11..52f506f0503 100644 --- a/addons/crm/data/mail_data.xml +++ b/addons/crm/data/mail_data.xml @@ -1,14 +1,6 @@ - - - - - - - - Opportunity Created diff --git a/addons/crm/models/res_config_settings.py b/addons/crm/models/res_config_settings.py index f01f8ea93c1..bccf20a322e 100644 --- a/addons/crm/models/res_config_settings.py +++ b/addons/crm/models/res_config_settings.py @@ -7,12 +7,6 @@ from odoo import api, fields, models class ResConfigSettings(models.TransientModel): _inherit = 'res.config.settings' - crm_alias_prefix = fields.Char( - 'Default Alias Name for Leads', - compute="_compute_crm_alias_prefix" , readonly=False, store=True) - generate_lead_from_alias = fields.Boolean( - 'Manual Assignment of Emails', config_parameter='crm.generate_lead_from_alias', - compute="_compute_generate_lead_from_alias", readonly=False, store=True) group_use_lead = fields.Boolean(string="Leads", implied_group='crm.group_use_lead') group_use_recurring_revenues = fields.Boolean(string="Recurring Revenues", implied_group='crm.group_use_recurring_revenues') module_crm_iap_lead = fields.Boolean("Generate new leads based on their country, industries, size, etc.") @@ -29,18 +23,6 @@ class ResConfigSettings(models.TransientModel): predictive_lead_scoring_fields = fields.Many2many('crm.lead.scoring.frequency.field', string='Lead Scoring Frequency Fields', compute="_compute_pls_fields", inverse="_inverse_pls_fields_str") predictive_lead_scoring_fields_str = fields.Char(string='Lead Scoring Frequency Fields in String', config_parameter='crm.pls_fields') - def _find_default_lead_alias_id(self): - alias = self.env.ref('crm.mail_alias_lead_info', False) - if not alias: - alias = self.env['mail.alias'].search([ - ('alias_model_id.model', '=', 'crm.lead'), - ('alias_force_thread_id', '=', False), - ('alias_parent_model_id.model', '=', 'crm.team'), - ('alias_parent_thread_id', '=', False), - ('alias_defaults', '=', '{}') - ], limit=1) - return alias - @api.depends('predictive_lead_scoring_fields_str') def _compute_pls_fields(self): """ As config_parameters does not accept m2m field, @@ -76,37 +58,8 @@ class ResConfigSettings(models.TransientModel): if setting.predictive_lead_scoring_start_date: setting.predictive_lead_scoring_start_date_str = fields.Date.to_string(setting.predictive_lead_scoring_start_date) - @api.depends('group_use_lead') - def _compute_generate_lead_from_alias(self): - """ Reset alias / leads configuration if leads are not used """ - for setting in self.filtered(lambda r: not r.group_use_lead): - setting.generate_lead_from_alias = False - - @api.depends('generate_lead_from_alias') - def _compute_crm_alias_prefix(self): - for setting in self: - setting.crm_alias_prefix = (setting.crm_alias_prefix or 'contact') if setting.generate_lead_from_alias else False - - @api.model - def get_values(self): - res = super(ResConfigSettings, self).get_values() - alias = self._find_default_lead_alias_id() - res.update( - crm_alias_prefix=alias.alias_name if alias else False, - ) - return res - def set_values(self): super(ResConfigSettings, self).set_values() - alias = self._find_default_lead_alias_id() - if alias: - alias.write({'alias_name': self.crm_alias_prefix}) - else: - self.env['mail.alias'].create({ - 'alias_name': self.crm_alias_prefix, - 'alias_model_id': self.env['ir.model']._get('crm.lead').id, - 'alias_parent_model_id': self.env['ir.model']._get('crm.team').id, - }) for team in self.env['crm.team'].search([]): team.alias_id.write(team._alias_get_creation_values()) diff --git a/addons/crm/views/res_config_settings_views.xml b/addons/crm/views/res_config_settings_views.xml index 7d38c8846d2..d5a8a937bad 100644 --- a/addons/crm/views/res_config_settings_views.xml +++ b/addons/crm/views/res_config_settings_views.xml @@ -66,32 +66,6 @@ -
-
- -
-
-
-

Lead Generation

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 2/4] [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): From 17aa8679a06f9a213ab5d5837c3a7c126d230d9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Thu, 17 Dec 2020 08:13:46 +0000 Subject: [PATCH 3/4] [IMP] crm: do not set environment user as responsible of leads created through gateway 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 We do not want to explicitly set an user as responsible when an incoming email creates a lead or an opportunity. We prefer that assignment is done either automatically (scoring) or manually. Using environment user would lead to set either root (gateway user - already prevented) either alias owner (through alias_user_id) either user sending email if email_from matches. Doing it also allows to exclude portal / public users that would send an email to the mailgateway. LINKS Task ID-2414079 COM PR odoo/odoo#63160 UPG PR odoo/upgrade#2017 --- addons/crm/models/crm_lead.py | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/addons/crm/models/crm_lead.py b/addons/crm/models/crm_lead.py index 4d99cb879c5..b7100c4824a 100644 --- a/addons/crm/models/crm_lead.py +++ b/addons/crm/models/crm_lead.py @@ -1397,17 +1397,12 @@ class Lead(models.Model): through message_process. This override updates the document according to the email. """ - - # remove external users - if self.env.user.has_group('base.group_portal'): - self = self.with_context(default_user_id=False) - # remove default author when going through the mail gateway. Indeed we - # do not want to explicitly set user_id to False; however we do not - # want the gateway user to be responsible if no other responsible is - # found. - if self._uid == self.env.ref('base.user_root').id: - self = self.with_context(default_user_id=False) + # do not want to explicitly set an user as responsible. We prefer that + # assignment is done automatically (scoring) or manually. Otherwise it + # would always be either root (gateway user) either alias owner (through + # alias_user_id). It also allows to exclude portal / public users. + self = self.with_context(default_user_id=False) if custom_values is None: custom_values = {} From 94de6b501bdf39bc4a246d085f75d2d5cef54491 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Thu, 17 Dec 2020 08:51:48 +0000 Subject: [PATCH 4/4] [IMP] crm: always hide alias left part when domain is not configured When alias domain is not configured always display "Configure a custom domain" link instead of an email having only a left-part or "Inactive alias" if left part is void. This is already the case in edit mode but not in read mode. New specification is * domain is not configured: display link in both read and edit mode; * domain is configured and left part is set: display alias; * domain is configured and left part is not set: display "Inactive alias" in read and display alias name for edition in edit; LINKS Task ID-2414079 COM PR odoo/odoo#63160 UPG PR odoo/upgrade#2017 --- addons/crm/views/crm_team_views.xml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/addons/crm/views/crm_team_views.xml b/addons/crm/views/crm_team_views.xml index 7eb900bca17..4ca2195f9d6 100644 --- a/addons/crm/views/crm_team_views.xml +++ b/addons/crm/views/crm_team_views.xml @@ -124,9 +124,10 @@
-
-
+ string="Email Alias" required="0" + attrs="{'invisible': [('alias_domain', '=', False)]}"/> +
+
@