diff --git a/addons/crm/models/crm_lead.py b/addons/crm/models/crm_lead.py index 8cd9098081f8cccc0134e861199154fa7db566a6..4e97f489e43c7cf4554705fa40de063d31071528 100644 --- a/addons/crm/models/crm_lead.py +++ b/addons/crm/models/crm_lead.py @@ -1684,6 +1684,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 2d6db0d17b5e10882e10e322fbeb47f883253fae..66023f62e1ad08582ebc6be0e526fd154150413e 100644 --- a/addons/crm/tests/test_crm_pls.py +++ b/addons/crm/tests/test_crm_pls.py @@ -399,3 +399,17 @@ class TestCRMPLS(TransactionCase): res_config_new = resConfig.new() self.assertEqual(fields.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) +