[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
This commit is contained in:
Thibault François
2021-05-12 14:02:15 +00:00
committed by Thibault Delavallée
parent 6106642cb5
commit d92ca08fd7
3 changed files with 10 additions and 4 deletions
+3 -2
View File
@@ -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)
]
# ------------------------------------------------------------
+6 -1
View File
@@ -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)
+1 -1
View File
@@ -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')