_name = "crm.lead"
_description = "Lead/Opportunity"
_order = "priority,date_action,id desc"
- _inherit = ['mail.thread','res.partner.address']
+ _inherit = ['mail.thread','res.partner']
def _read_group_stage_ids(self, cr, uid, ids, domain, read_group_order=None, access_rights_uid=None, context=None):
access_rights_uid = access_rights_uid or uid
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"),
# Only used for type opportunity
- 'partner_address_id': fields.many2one('res.partner.address', 'Partner Contact', domain="[('partner_id','=',partner_id)]"),
'probability': fields.float('Probability (%)',group_operator="avg"),
'planned_revenue': fields.float('Expected Revenue'),
'ref': fields.reference('Reference', selection=crm._links_get, size=128),
'title_action': fields.char('Next Action', size=64),
'stage_id': fields.many2one('crm.case.stage', 'Stage', domain="[('section_ids', '=', section_id)]"),
'color': fields.integer('Color Index'),
- 'partner_address_name': fields.related('partner_address_id', 'name', type='char', string='Partner Contact Name', readonly=True),
- 'partner_address_email': fields.related('partner_address_id', 'email', type='char', string='Partner Contact Email', readonly=True),
+ 'partner_address_name': fields.related('partner_id', 'name', type='char', string='Partner Contact Name', readonly=True),
+ 'partner_address_email': fields.related('partner_id', 'email', type='char', string='Partner Contact Email', readonly=True),
'company_currency': fields.related('company_id', 'currency_id', 'symbol', type='char', string='Company Currency', readonly=True),
'user_email': fields.related('user_id', 'user_email', type='char', string='User Email', readonly=True),
'user_login': fields.related('user_id', 'login', type='char', string='User Login', readonly=True),
"""
if not add:
return {'value': {'email_from': False, 'country_id': False}}
- address = self.pool.get('res.partner.address').browse(cr, uid, add)
+ address = self.pool.get('res.partner').browse(cr, uid, add)
return {'value': {'email_from': address.email, 'phone': address.phone, 'country_id': address.country_id.id}}
def on_change_optin(self, cr, uid, ids, optin):
first_opportunity = opportunities_list[0]
tail_opportunities = opportunities_list[1:]
- fields = ['partner_id', 'title', 'name', 'categ_id', 'channel_id', 'city', 'company_id', 'contact_name', 'country_id',
- 'partner_address_id', 'type_id', 'user_id', 'section_id', 'state_id', 'description', 'email', 'fax', 'mobile',
+ fields = ['partner_id', 'title', 'name', 'categ_id', 'channel_id', 'city', 'company_id', 'contact_name', 'country_id', 'type_id', 'user_id', 'section_id', 'state_id', 'description', 'email', 'fax', 'mobile',
'partner_name', 'phone', 'probability', 'planned_revenue', 'street', 'street2', 'zip', 'create_date', 'date_action_last',
'date_action_next', 'email_from', 'email_cc', 'partner_name']
'stage_id': stage_id or False,
'date_action': time.strftime('%Y-%m-%d %H:%M:%S'),
'date_open': time.strftime('%Y-%m-%d %H:%M:%S'),
- 'partner_address_id': contact_id,
}
def _convert_opportunity_notification(self, cr, uid, lead, context=None):
}, 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
'date' : schedule_time,
'section_id' : section_id or False,
'partner_id': lead.partner_id and lead.partner_id.id or False,
- 'partner_address_id': lead.partner_address_id and lead.partner_address_id.id or False,
- 'partner_phone' : phone or lead.phone or (lead.partner_address_id and lead.partner_address_id.phone or False),
- 'partner_mobile' : lead.partner_address_id and lead.partner_address_id.mobile or False,
+ 'partner_phone' : phone or lead.phone or (lead.partner_id and lead.partner_id.phone or False),
+ 'partner_mobile' : lead.partner_id and lead.partner_id.mobile or False,
'priority': lead.priority,
}
select=True, help='Sales team to which Case belongs to.'),
'user_id': fields.many2one('res.users', 'Responsible'),
'partner_id': fields.many2one('res.partner', 'Partner'),
- 'partner_address_id': fields.many2one('res.partner.address', 'Partner Contact', \
- domain="[('partner_id','=',partner_id)]"),
'company_id': fields.many2one('res.company', 'Company'),
'description': fields.text('Description'),
'state': fields.selection([
domain="['|',('section_id','=',section_id),('section_id','=',False),\
('object_id.model', '=', 'crm.phonecall')]"),
'partner_phone': fields.char('Phone', size=32),
- 'partner_contact': fields.related('partner_address_id', 'name', \
- type="char", string="Contact", size=128),
'partner_mobile': fields.char('Mobile', size=32),
'priority': fields.selection(crm.AVAILABLE_PRIORITIES, 'Priority'),
'date_closed': fields.datetime('Closed', readonly=True),
res = super(crm_phonecall, self).onchange_partner_address_id(cr, uid, ids, add, email)
res.setdefault('value', {})
if add:
- address = self.pool.get('res.partner.address').browse(cr, uid, add)
+ address = self.pool.get('res.partner').browse(cr, uid, add)
res['value']['partner_phone'] = address.phone
res['value']['partner_mobile'] = address.mobile
return res
'date' : schedule_time,
'section_id' : section_id or False,
'partner_id': call.partner_id and call.partner_id.id or False,
- 'partner_address_id': call.partner_address_id and call.partner_address_id.id or False,
'partner_phone' : call.partner_phone,
'partner_mobile' : call.partner_mobile,
'priority': call.priority,
return self.write(cr, uid, ids, {'partner_id' : partner_id}, context=context)
def _call_create_partner_address(self, cr, uid, phonecall, partner_id, context=None):
- address = self.pool.get('res.partner.address')
+ address = self.pool.get('res.partner')
return address.create(cr, uid, {
- 'partner_id': partner_id,
- 'parent_id': parent_id,
++ 'parent_id': partner_id,
'name': phonecall.name,
'phone': phonecall.partner_phone,
})
def convert_opportunity(self, cr, uid, ids, opportunity_summary=False, partner_id=False, planned_revenue=0.0, probability=0.0, context=None):
partner = self.pool.get('res.partner')
- address = self.pool.get('res.partner.address')
opportunity = self.pool.get('crm.lead')
opportunity_dict = {}
default_contact = False
if partner_id:
address_id = partner.address_get(cr, uid, [partner_id])['default']
if address_id:
- default_contact = address.browse(cr, uid, address_id, context=context)
+ default_contact = partner.browse(cr, uid, address_id, context=context)
opportunity_id = opportunity.create(cr, uid, {
'name': opportunity_summary or call.name,
'planned_revenue': planned_revenue,
'probability': probability,
'partner_id': partner_id or False,
- 'partner_address_id': default_contact and default_contact.id,
- 'phone': default_contact and default_contact.phone,
'mobile': default_contact and default_contact.mobile,
'section_id': call.section_id and call.section_id.id or False,
'description': call.description or False,