diff --git a/addons/crm/models/crm_lead.py b/addons/crm/models/crm_lead.py index 655446cbb48..d07c1d52581 100644 --- a/addons/crm/models/crm_lead.py +++ b/addons/crm/models/crm_lead.py @@ -1956,6 +1956,9 @@ class Lead(models.Model): total_won = team_won if field == 'stage_id' else field_result['won_total'] total_lost = team_lost if field == 'stage_id' else field_result['lost_total'] + # if one count = 0, we cannot compute lead probability + if not total_won or not total_lost: + continue s_lead_won *= value_result['won'] / total_won s_lead_lost *= value_result['lost'] / total_lost diff --git a/addons/crm/tests/test_crm_pls.py b/addons/crm/tests/test_crm_pls.py index cda14e08da0..b34cc0c6824 100644 --- a/addons/crm/tests/test_crm_pls.py +++ b/addons/crm/tests/test_crm_pls.py @@ -500,6 +500,19 @@ class TestCRMPLS(TransactionCase): self.assertEqual(Date.to_string(res_config_new.predictive_lead_scoring_start_date), str_date_8_days_ago, "If config param is not a valid date, date in settings should be set to 8 days before today") + def test_pls_no_share_stage(self): + """ We test here the situation where all stages are team specific, as there is + a current limitation (can be seen in _pls_get_won_lost_total_count) regarding + the first stage (used to know how many lost and won there is) that requires + to have no team assigned to it.""" + Lead = self.env['crm.lead'] + team_id = self.env['crm.team'].create([{'name': 'Team Test'}]).id + self.env['crm.stage'].search([('team_id', '=', False)]).write({'team_id': team_id}) + lead = Lead.create({'name': 'team', 'team_id': team_id, 'probability': 41.23}) + Lead._cron_update_automated_probabilities() + self.assertEqual(tools.float_compare(lead.probability, 41.23, 2), 0) + self.assertEqual(tools.float_compare(lead.automated_probability, 0, 2), 0) + @users('user_sales_manager') def test_team_unlink(self): """ Test that frequencies are sent to "no team" when unlinking a team