[FIX] crm: compute lead probability on kanban quick create
-In CRM, click the CREATE button. -Only enter a title for the new lead and directly click ADD. -Click on the newly created lead to view its details. Before this commit: although a probability could be computed based on the stage of the lead, this field has a default value and, at creation time, this value doesn't end up in the list of values from which the `_write_probability` function decide whether to recompute the probability. After this commit: The `_write_probability` function, renamed `_update_probability`, doesn't check whether it should or not update the probability. It just does it. This function is directly called in the `create`. `_should_update_probability` is called before `_update_probability` in the `write`. Task ID : 2081480 closes odoo/odoo#40411 X-original-commit: 483a94116629e418ebb224bad375747cf9ab3c1d Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
This commit is contained in:
committed by
fw-bot
parent
a8fdda6638
commit
c9bed78c2b
@@ -401,7 +401,7 @@ class Lead(models.Model):
|
||||
|
||||
result = super(Lead, self.with_context(context)).create(vals)
|
||||
# Compute new probability for each lead separately
|
||||
result._write_probability(vals)
|
||||
result._update_probability()
|
||||
return result
|
||||
|
||||
def write(self, vals):
|
||||
@@ -424,20 +424,12 @@ class Lead(models.Model):
|
||||
|
||||
write_result = super(Lead, self).write(vals)
|
||||
# Compute new automated_probability (and, eventually, probability) for each lead separately
|
||||
self._write_probability(vals)
|
||||
if self._should_update_probability(vals):
|
||||
self._update_probability()
|
||||
|
||||
return write_result
|
||||
|
||||
def _write_probability(self, vals):
|
||||
compute = False
|
||||
fields_to_check = ['tag_ids', 'stage_id', 'team_id'] + self._pls_get_safe_fields()
|
||||
for field, value in vals.items():
|
||||
if field in fields_to_check:
|
||||
compute = True
|
||||
break
|
||||
|
||||
if not compute:
|
||||
return
|
||||
def _update_probability(self):
|
||||
lead_probabilities = self._pls_get_naive_bayes_probabilities()
|
||||
for lead in self:
|
||||
if lead.id in lead_probabilities:
|
||||
@@ -448,6 +440,13 @@ class Lead(models.Model):
|
||||
super(Lead, lead).write(proba_vals)
|
||||
return
|
||||
|
||||
def _should_update_probability(self, vals):
|
||||
fields_to_check = ['tag_ids', 'stage_id', 'team_id'] + self._pls_get_safe_fields()
|
||||
for field, value in vals.items():
|
||||
if field in fields_to_check:
|
||||
return True
|
||||
return False
|
||||
|
||||
@api.returns('self', lambda value: value.id)
|
||||
def copy(self, default=None):
|
||||
self.ensure_one()
|
||||
|
||||
Reference in New Issue
Block a user