summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Beguin <dbe@odoo.com>2020-04-06 10:16:10 +0000
committerThibault Delavallée <tde@odoo.com>2020-04-20 08:49:26 +0000
commit755e00bdcd792ef5a788963212048cd1d15ce241 (patch)
tree4a6b5a823658e35637a83836fd95f35931725d6c
parentfa55c0e96399667a954cb2addc7a585585ca9bd7 (diff)
[FIX] crm: reset auto probability if auto probability could not be computed
Or, in other words, set auto probability to 0 if no statistics yet. Before this commit, if the automated probability could not be computed, the automated_probability field on crm.lead was not modified. That led to having leads stuck at 100% once won, even if going back to another stage. This happened only : - in an empty DB (no demo data) or - in a DB where the PLS cron had never ran and the PLS threshold was inactivated (=0). Because, if the frequency table has never been built, we cannot compute the automated probability. After this commit, if the automated probability cannot be computed, we set it by default to 0. If the probability and the automated probability was aligned, probability is also set to 0. Note: this could be an issue if both probabilities were aligned, then someone deactivate the PLS cron and set the threshold to 0 (if not yet the case), and clear the frequency table. (unlikely to happen but still..) When updating updating a lead, we would lose the probability -> auto proba set to 0 + proba set to 0 as they were aligned. Task ID: 2232036 closes odoo/odoo#49766 X-original-commit: b43ecf73958273a126135966422112b90f9f12cc Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
-rw-r--r--addons/crm/models/crm_lead.py11
1 files changed, 5 insertions, 6 deletions
diff --git a/addons/crm/models/crm_lead.py b/addons/crm/models/crm_lead.py
index d71d4bf6ec3..fb5c891e377 100644
--- a/addons/crm/models/crm_lead.py
+++ b/addons/crm/models/crm_lead.py
@@ -399,12 +399,11 @@ class Lead(models.Model):
def _update_probability(self):
lead_probabilities = self.sudo()._pls_get_naive_bayes_probabilities()
for lead in self:
- if lead.id in lead_probabilities:
- lead_proba = lead_probabilities[lead.id]
- proba_vals = {'automated_probability': lead_proba}
- if lead.active and lead.is_automated_probability:
- proba_vals['probability'] = lead_proba
- super(Lead, lead).write(proba_vals)
+ lead_proba = lead_probabilities.get(lead.id, 0)
+ proba_vals = {'automated_probability': lead_proba}
+ if lead.is_automated_probability:
+ proba_vals = {'probability': lead_proba}
+ super(Lead, lead).write(proba_vals)
return
def _should_update_probability(self, vals):