From d92ca08fd72b0c74d64823c6b4888a7ceb740efe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Fran=C3=A7ois?= Date: Fri, 30 Apr 2021 15:05:21 +0000 Subject: [PATCH] [IMP] crm: count all leads in ``lead_month_count`` used in assign PURPOSE Goal of ``assignment_max`` is to make sure sales receives this amount of leads within 30 days. Counting lost or won leads is therefore necessary to effectively count all leads received those last 30 days. SPECIFICATIONS Change ``lead_month_count`` computation to take into account archived and won leads. We consider now that goal of ``assignment_max`` is to make sure sales people receive this amount of leads within the 30 days at max. This allows to avoid archiving leads to get a new batch of leads to handle. Also done leads should be counted as it is part of the month job. LINKS Task ID-2444908 (assign fixes) Task ID-2489951 (assign process improvements) COM PR odoo/odoo#70172 X-original-commit: 23feb1a467e0a441eb775be26c96af697d74506f --- addons/crm/models/crm_team_member.py | 5 +++-- addons/crm/tests/test_crm_lead_assignment.py | 7 ++++++- addons/crm/tests/test_crm_lead_convert.py | 2 +- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/addons/crm/models/crm_team_member.py b/addons/crm/models/crm_team_member.py index 779ab038a7f..79610f08e2f 100644 --- a/addons/crm/models/crm_team_member.py +++ b/addons/crm/models/crm_team_member.py @@ -31,7 +31,9 @@ class Team(models.Model): def _compute_lead_month_count(self): for member in self: if member.user_id.id and member.crm_team_id.id: - member.lead_month_count = self.env['crm.lead'].search_count(member._get_lead_month_domain()) + member.lead_month_count = self.env['crm.lead'].with_context(active_test=False).search_count( + member._get_lead_month_domain() + ) else: member.lead_month_count = 0 @@ -54,7 +56,6 @@ class Team(models.Model): ('user_id', '=', self.user_id.id), ('team_id', '=', self.crm_team_id.id), ('date_open', '>=', limit_date), - ('probability', '<', 100) ] # ------------------------------------------------------------ diff --git a/addons/crm/tests/test_crm_lead_assignment.py b/addons/crm/tests/test_crm_lead_assignment.py index af2c75c56ac..11a5c953176 100644 --- a/addons/crm/tests/test_crm_lead_assignment.py +++ b/addons/crm/tests/test_crm_lead_assignment.py @@ -143,9 +143,14 @@ class TestLeadAssign(TestLeadAssignCommon): existing_leads.flush() self.members.invalidate_cache(fnames=['lead_month_count']) - self.assertEqual(self.sales_team_1_m3.lead_month_count, 12) + self.assertEqual(self.sales_team_1_m3.lead_month_count, 14) self.assertEqual(self.sales_team_convert_m1.lead_month_count, 0) + # re-assign existing leads, check monthly count is updated + existing_leads[-2:]._handle_salesmen_assignment(user_ids=self.user_sales_manager.ids) + self.members.invalidate_cache(fnames=['lead_month_count']) + self.assertEqual(self.sales_team_1_m3.lead_month_count, 12) + with self.with_user('user_sales_manager'): self.env['crm.team'].browse(self.sales_team_1.ids)._action_assign_leads(work_days=4) diff --git a/addons/crm/tests/test_crm_lead_convert.py b/addons/crm/tests/test_crm_lead_convert.py index 518c0d877c9..170b79e5cc5 100644 --- a/addons/crm/tests/test_crm_lead_convert.py +++ b/addons/crm/tests/test_crm_lead_convert.py @@ -97,7 +97,7 @@ class TestLeadConvert(crm_common.TestLeadConvertCommon): } ]) lead_lost = dup_leads.filtered(lambda lead: lead.name == 'Duplicate lead: same email_from, lost') - opp_proba100 = dup_leads.filtered(lambda lead: lead.name == 'Duplicate opp: same email_from, proba 100 but not won') + _opp_proba100 = dup_leads.filtered(lambda lead: lead.name == 'Duplicate opp: same email_from, proba 100 but not won') opp_won = dup_leads.filtered(lambda lead: lead.name == 'Duplicate opp: same email_from, won') opp_lost = dup_leads.filtered(lambda lead: lead.name == 'Duplicate: lost opportunity')