domain="['|',('section_id','=',section_id),('section_id','=',False)]", help="From which campaign (seminar, marketing campaign, mass mailing, ...) did this contact come from?"),
'channel_id': fields.many2one('crm.case.channel', 'Channel', help="Communication channel (mail, direct, phone, ...)"),
'contact_name': fields.char('Contact Name', size=64),
-- 'partner_name': fields.char("Customer Name", size=64,help='The name of the future partner that will be created while converting the lead into opportunity', select=1),
++ 'partner_name': fields.char("Customer Name", size=64,help='The name of the future partner company that will be created while converting the lead into opportunity', select=1),
'optin': fields.boolean('Opt-In', help="If opt-in is checked, this contact has accepted to receive emails."),
'optout': fields.boolean('Opt-Out', help="If opt-out is checked, this contact has refused to receive emails or unsubscribed to a campaign."),
'type':fields.selection([ ('lead','Lead'), ('opportunity','Opportunity'), ],'Type', help="Type is used to separate Leads and Opportunities"),
}, context=context)
return True
-- def _lead_create_partner(self, cr, uid, lead, context=None):
++ def _lead_create_contact(self, cr, uid, lead, name, is_company, parent_id=False, context=None):
partner = self.pool.get('res.partner')
-- partner_id = partner.create(cr, uid, {
-- 'name': lead.partner_name or lead.contact_name or lead.name,
-- 'user_id': lead.user_id.id,
-- 'comment': lead.description,
-- 'section_id': lead.section_id.id or False,
-- 'address': []
-- })
++ vals = { 'name': name,
++ 'user_id': lead.user_id.id,
++ 'comment': lead.description,
++ 'section_id': lead.section_id.id or False,
++ 'parent_id': parent_id,
++ 'phone': lead.phone,
++ 'mobile': lead.mobile,
++ 'email': lead.email_from and to_email(lead.email_from)[0],
++ 'fax': lead.fax,
++ 'title': lead.title and lead.title.id or False,
++ 'function': lead.function,
++ 'street': lead.street,
++ 'street2': lead.street2,
++ 'zip': lead.zip,
++ 'city': lead.city,
++ 'country_id': lead.country_id and lead.country_id.id or False,
++ 'state_id': lead.state_id and lead.state_id.id or False,
++ 'is_company': is_company,
++ }
++
++ partner = partner.create(cr, uid,vals, context)
++ return partner
++
++ def _create_lead_partner(self, cr, uid, lead, context=None):
++ partner_id = False
++ if lead.partner_name and lead.contact_name:
++ partner_id = self._lead_create_contact(cr, uid, lead, lead.partner_name, 'partner', context=context)
++ self._lead_create_contact(cr, uid, lead, lead.contact_name, 'contact', partner_id, context=context)
++ elif lead.partner_name and not lead.contact_name:
++ partner_id = self._lead_create_contact(cr, uid, lead, lead.partner_name, 'partner', context=context)
++ elif not lead.partner_name and lead.contact_name:
++ partner_id = self._lead_create_contact(cr, uid, lead, lead.contact_name, 'contact', context=context)
++ else:
++ partner_id = self._lead_create_contact(cr, uid, lead, lead.name, 'contact', context=context)
return partner_id
def _lead_set_partner(self, cr, uid, lead, partner_id, context=None):
if partner_id:
res_partner.write(cr, uid, partner_id, {'section_id': lead.section_id.id or False})
contact_id = res_partner.address_get(cr, uid, [partner_id])['default']
- res = lead.write({'partner_id' : partner_id, 'partner_address_id': contact_id}, context=context)
-
+ res = lead.write({'partner_id' : partner_id, }, context=context)
-
return res
-- def _lead_create_partner_address(self, cr, uid, lead, partner_id, context=None):
- address = self.pool.get('res.partner.address')
- return address.create(cr, uid, {
- 'partner_id': partner_id,
- 'name': lead.contact_name,
- 'phone': lead.phone,
- 'mobile': lead.mobile,
- 'email': lead.email_from and to_email(lead.email_from)[0],
- 'fax': lead.fax,
- 'title': lead.title and lead.title.id or False,
- 'function': lead.function,
- 'street': lead.street,
- 'street2': lead.street2,
- 'zip': lead.zip,
- 'city': lead.city,
- 'country_id': lead.country_id and lead.country_id.id or False,
- 'state_id': lead.state_id and lead.state_id.id or False,
- })
-
- address = self.pool.get('res.partner')
- return address.create(cr, uid, {
- 'parent_id': partner_id,
- 'name': lead.contact_name,
- 'phone': lead.phone,
- 'mobile': lead.mobile,
- 'email': lead.email_from and to_email(lead.email_from)[0],
- 'fax': lead.fax,
- 'title': lead.title and lead.title.id or False,
- 'function': lead.function,
- 'street': lead.street,
- 'street2': lead.street2,
- 'zip': lead.zip,
- 'city': lead.city,
- 'country_id': lead.country_id and lead.country_id.id or False,
- 'state_id': lead.state_id and lead.state_id.id or False,
- })
-
def convert_partner(self, cr, uid, ids, action='create', partner_id=False, context=None):
"""
This function convert partner based on action.
for lead in self.browse(cr, uid, ids, context=context):
if action == 'create':
if not partner_id:
-- partner_id = self._lead_create_partner(cr, uid, lead, context=context)
-- self._lead_create_partner_address(cr, uid, lead, partner_id, context=context)
++ partner_id = self._create_lead_partner(cr, uid, lead, context)
self._lead_set_partner(cr, uid, lead, partner_id, context=context)
partner_ids[lead.id] = partner_id
return partner_ids