[FIX] crm_iap_lead_enrich : fix lost semantic in lead iap_enrich process

Since the default value of probability is not set anymore,
the probability of a new lead is equivalent to 0.
In Lead enrichement, we filter out won and lost leads.
But probability = 0 is not a good ways anymore to filter out lost leads.
Lost reprensents archived leads.

Task ID: 2044539
PR #37413
This commit is contained in:
David Beguin
2019-09-25 14:42:31 +00:00
parent b8dda50aaa
commit b8401b09f8
@@ -19,10 +19,11 @@ class Lead(models.Model):
@api.model
def _iap_enrich_leads_cron(self):
timeDelta = fields.datetime.now() - datetime.timedelta(hours=1)
# Get all leads not lost nor won (lost: active = False)
leads = self.search([
('iap_enrich_done', '=', False),
('reveal_id', '=', False),
('probability', 'not in', (0, 100)),
('probability', '<', 100),
('create_date', '>', timeDelta)
])
leads._iap_enrich(from_cron=True)
@@ -30,7 +31,8 @@ class Lead(models.Model):
def _iap_enrich(self, from_cron=False):
lead_emails = {}
for lead in self:
if lead.probability in (0, 100) or lead.iap_enrich_done:
# If lead is lost, active == False, but is anyway removed from the search in the cron.
if lead.probability == 100 or lead.iap_enrich_done:
continue
normalized_email = tools.email_normalize(lead.partner_address_email) or tools.email_normalize(lead.email_from)
if normalized_email: