From 8fd106636746f998c100f88581740bb77814048d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Fri, 18 Dec 2020 13:09:38 +0000 Subject: [PATCH] [REF] crm: improve team opt-out from lead automatic assignment GLOBAL PURPOSE Ability to have salesmen belonging to several sales team is a core requirement of CRM. It is therefore moved from website_crm_score to crm along with cleaning and behavior improvement. Automatic lead assignment is also moved and cleaned. SPECIFICATIONS: TEAM OPT-OUT OF ASSIGN Allow teams to individually opt-out automatic assignment. If automatic assignment is activated one can make some team opt-out of automatic process. Manual assignment on team through an action button is possible even when opt-outed. Allow teams to individually opt-out automatic assignment. If automatic assignment is activated one can make some team opt-out of automatic process. Manual assignment on team through an action button is possible even when opt-outed. SPECIFICATIONS: RESTRICT ASSIGN TO OPPORTUNITIES ENABLED TEAMS Only teams with use_leads or use_oppotunities should be included in automatic assign. Indeed other teams like POS, website) do not handle opportunities or leads. Automatically assigning them leads makes no sense. LINKS Task ID-2086889 (main task) Task ID-2357969 (scoring migration task) Community PR odoo/odoo#48422 Enterprise PR odoo/enterprise#499 Upgrade PR odoo/upgrade#996 --- addons/crm/models/crm_team.py | 6 +++++- addons/crm/models/res_config_settings.py | 2 +- addons/crm/views/crm_team_views.xml | 3 ++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/addons/crm/models/crm_team.py b/addons/crm/models/crm_team.py index 863e63758d5..d75237bf5ad 100644 --- a/addons/crm/models/crm_team.py +++ b/addons/crm/models/crm_team.py @@ -29,6 +29,7 @@ class Team(models.Model): # assignment assignment_enabled = fields.Boolean('Lead Assign', compute='_compute_assignment_enabled') assignment_auto_enabled = fields.Boolean('Auto Assignment', compute='_compute_assignment_enabled') + assignment_optout = fields.Boolean('Skip auto assignment') assignment_max = fields.Integer( 'Lead Capacity', compute='_compute_assignment_max', help='Monthly leads for all salesmen belonging to the team') @@ -188,7 +189,10 @@ class Team(models.Model): elif assign_cron.interval_type == 'days': work_days = 2 * assign_cron.interval_number * 1 work_days = 30 if work_days > 30 else work_days - self.env['crm.team'].search([])._action_assign_leads(work_days=work_days) + self.env['crm.team'].search([ + '&', '|', ('use_leads', '=', True), ('use_opportunities', '=', True), + ('assignment_optout', '=', False) + ])._action_assign_leads(work_days=work_days) return True def action_assign_leads(self, work_days=2): diff --git a/addons/crm/models/res_config_settings.py b/addons/crm/models/res_config_settings.py index 0a877b4239b..2afe466fc5c 100644 --- a/addons/crm/models/res_config_settings.py +++ b/addons/crm/models/res_config_settings.py @@ -144,4 +144,4 @@ class ResConfigSettings(models.TransientModel): def action_crm_assign_leads(self): self.ensure_one() - return self.env['crm.team'].search([]).action_assign_leads() + return self.env['crm.team'].search([('assignment_optout', '=', False)]).action_assign_leads() diff --git a/addons/crm/views/crm_team_views.xml b/addons/crm/views/crm_team_views.xml index 9645e465b1d..89ff7769940 100644 --- a/addons/crm/views/crm_team_views.xml +++ b/addons/crm/views/crm_team_views.xml @@ -112,7 +112,7 @@ string="Assign Leads" class="oe_highlight" confirm="This will assign leads to all members. Do you want to proceed?" - attrs="{'invisible': [('assignment_enabled', '=', False)]}"/> + attrs="{'invisible': ['|', '&', ('use_leads', '=', False), ('use_opportunities', '=', False), ('assignment_enabled', '=', False)]}"/> @@ -162,6 +162,7 @@ / + {'invisible': [('assignment_enabled', '=', True)]}