[FIX] crm: crm to opp, get duplidated leads does not take losts and deads. + search algorithm imp
bzr revid: dle@openerp.com-20140312155453-fj9ngb988advvn8s
This commit is contained in:
parent
5bf1608278
commit
387dc3c911
|
@ -42,19 +42,22 @@ class crm_lead2opportunity_partner(osv.osv_memory):
|
|||
return {'value': {'partner_id': False if action != 'exist' else self._find_matching_partner(cr, uid, context=context)}}
|
||||
|
||||
def _get_duplicated_leads(self, cr, uid, partner_id, email, context=None):
|
||||
"""
|
||||
Search for opportunities that have the same partner and that arent done or cancelled
|
||||
"""
|
||||
lead_obj = self.pool.get('crm.lead')
|
||||
results = []
|
||||
if partner_id:
|
||||
# Search for opportunities that have the same partner and that arent done or cancelled
|
||||
ids = lead_obj.search(cr, uid, [('partner_id', '=', partner_id), '|', ('stage_id.probability', '=', False), ('stage_id.probability', '<', '100')])
|
||||
for id in ids:
|
||||
results.append(id)
|
||||
email = re.findall(r'([^ ,<@]+@[^> ,]+)', email or '')
|
||||
final_stage_domain = [('stage_id.probability', '<', 100), '|', ('stage_id.probability', '>', 0), ('stage_id.sequence', '<=', 1)]
|
||||
partner_match_domain = []
|
||||
if email:
|
||||
ids = lead_obj.search(cr, uid, [('email_from', '=ilike', email[0]), '|', ('stage_id.probability', '=', False), ('stage_id.probability', '<', '100')])
|
||||
for id in ids:
|
||||
results.append(id)
|
||||
return list(set(results))
|
||||
partner_match_domain.append(('email_from', '=ilike', email[0]))
|
||||
if partner_id:
|
||||
partner_match_domain.append(('partner_id', '=', partner_id))
|
||||
if email and partner_id:
|
||||
partner_match_domain.insert(0, '|')
|
||||
if not partner_match_domain:
|
||||
return []
|
||||
return lead_obj.search(cr, uid, partner_match_domain + final_stage_domain)
|
||||
|
||||
|
||||
def default_get(self, cr, uid, fields, context=None):
|
||||
|
|
Loading…
Reference in New Issue