[IMP]: crm: Improvement in lead to opportunity wizard for partner selection
bzr revid: rpa@tinyerp.com-20101007135352-8w96zvhrvqlhzk0w
This commit is contained in:
parent
d180cd91eb
commit
efee86963f
|
@ -162,41 +162,7 @@ class crm_lead2opportunity_partner(osv.osv_memory):
|
|||
'partner_id': fields.many2one('res.partner', 'Partner'),
|
||||
'action': fields.selection([('exist', 'Link to an existing partner'), ('create', 'Create a new partner')], 'Action'),
|
||||
}
|
||||
|
||||
def default_get(self, cr, uid, fields, context=None):
|
||||
"""
|
||||
This function gets default values
|
||||
@param self: The object pointer
|
||||
@param cr: the current row, from the database cursor,
|
||||
@param uid: the current user’s ID for security checks,
|
||||
@param fields: List of fields for default value
|
||||
@param context: A standard dictionary for contextual values
|
||||
|
||||
@return : default values of fields.
|
||||
"""
|
||||
lead_obj = self.pool.get('crm.lead')
|
||||
partner_obj = self.pool.get('res.partner')
|
||||
contact_obj = self.pool.get('res.partner.address')
|
||||
partner_id = False
|
||||
|
||||
data = context and context.get('active_ids', []) or []
|
||||
res = super(crm_lead2opportunity_partner, self).default_get(cr, uid, fields, context=context)
|
||||
|
||||
for lead in lead_obj.browse(cr, uid, data, context=context):
|
||||
partner_ids = partner_obj.search(cr, uid, [('name', '=', lead.partner_name or lead.name)])
|
||||
if not partner_ids and lead.email_from:
|
||||
address_ids = contact_obj.search(cr, uid, [('email', '=', lead.email_from)])
|
||||
if address_ids:
|
||||
addresses = contact_obj.browse(cr, uid, address_ids)
|
||||
partner_ids = addresses and [addresses[0].partner_id.id] or False
|
||||
partner_id = partner_ids and partner_ids[0] or False
|
||||
|
||||
if 'partner_id' in fields:
|
||||
res.update({'partner_id': partner_id})
|
||||
if 'action' in fields:
|
||||
res.update({'action': partner_id and 'exist' or 'create'})
|
||||
return res
|
||||
|
||||
def make_partner(self, cr, uid, ids, context=None):
|
||||
"""
|
||||
This function Makes partner based on action.
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
|
||||
from osv import osv, fields
|
||||
from tools.translate import _
|
||||
import re
|
||||
|
||||
class crm_lead2partner(osv.osv_memory):
|
||||
""" Converts lead to partner """
|
||||
|
@ -74,12 +75,19 @@ class crm_lead2partner(osv.osv_memory):
|
|||
res = super(crm_lead2partner, self).default_get(cr, uid, fields, context=context)
|
||||
|
||||
for lead in lead_obj.browse(cr, uid, data, context=context):
|
||||
partner_ids = partner_obj.search(cr, uid, [('name', '=', lead.partner_name or lead.name)])
|
||||
if not partner_ids and lead.email_from:
|
||||
address_ids = contact_obj.search(cr, uid, [('email', '=', lead.email_from)])
|
||||
partner_ids = []
|
||||
if lead.email_from:
|
||||
email = re.findall(r'([^ ,<@]+@[^> ,]+)', lead.email_from)
|
||||
address_ids = contact_obj.search(cr, uid, [('email', 'in', email)])
|
||||
if address_ids:
|
||||
addresses = contact_obj.browse(cr, uid, address_ids)
|
||||
partner_ids = addresses and [addresses[0].partner_id.id] or False
|
||||
if not partner_ids and lead.partner_name:
|
||||
partner_ids = partner_obj.search(cr, uid, [('name', '=', lead.partner_name)], context=context)
|
||||
if not partner_ids:
|
||||
cr.execute("""SELECT p.id from res_partner p
|
||||
where regexp_replace(lower(p.name), '[^a-z]*', '', 'g') = regexp_replace(%s, '[^a-z]*', '', 'g')""", (lead.name.lower(), ))
|
||||
partner_ids = map(lambda x: x[0], cr.fetchall())
|
||||
partner_id = partner_ids and partner_ids[0] or False
|
||||
|
||||
if 'partner_id' in fields:
|
||||
|
|
Loading…
Reference in New Issue