[FIX] crm: mass convert opportunity - fix partner conversion + salesman assign
Low-risk hacky fix suitable for stable branch bzr revid: odo@openerp.com-20120424164939-232fvm574feq6y8b
This commit is contained in:
@@ -570,8 +570,6 @@ class crm_lead(crm_case, osv.osv):
|
||||
for lead in self.browse(cr, uid, ids, context=context):
|
||||
if lead.state in ('done', 'cancel'):
|
||||
continue
|
||||
if user_ids or section_id:
|
||||
self.allocate_salesman(cr, uid, [lead.id], user_ids, section_id, context=context)
|
||||
|
||||
vals = self._convert_opportunity_data(cr, uid, lead, customer, section_id, context=context)
|
||||
self.write(cr, uid, [lead.id], vals, context=context)
|
||||
@@ -583,6 +581,10 @@ class crm_lead(crm_case, osv.osv):
|
||||
mail_message.write(cr, uid, msg_ids, {
|
||||
'partner_id': lead.partner_id.id
|
||||
}, context=context)
|
||||
|
||||
if user_ids or section_id:
|
||||
self.allocate_salesman(cr, uid, ids, user_ids, section_id, context=context)
|
||||
|
||||
return True
|
||||
|
||||
def _lead_create_partner(self, cr, uid, lead, context=None):
|
||||
@@ -634,10 +636,10 @@ class crm_lead(crm_case, osv.osv):
|
||||
if context is None:
|
||||
context = {}
|
||||
partner_ids = {}
|
||||
force_partner_id = partner_id
|
||||
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)
|
||||
partner_id = force_partner_id or self._lead_create_partner(cr, uid, lead, context=context)
|
||||
self._lead_create_partner_address(cr, uid, lead, partner_id, context=context)
|
||||
self._lead_set_partner(cr, uid, lead, partner_id, context=context)
|
||||
partner_ids[lead.id] = partner_id
|
||||
|
||||
@@ -106,11 +106,23 @@ class crm_lead2opportunity_partner(osv.osv_memory):
|
||||
if context is None:
|
||||
context = {}
|
||||
lead = self.pool.get('crm.lead')
|
||||
partner_id = self._create_partner(cr, uid, ids, context=context)
|
||||
res = False
|
||||
if context.get('mass_convert'):
|
||||
partner_ids_map = self._create_partner(cr, uid, ids, context=context)
|
||||
else:
|
||||
partner_id = self._create_partner(cr, uid, ids, context=context)
|
||||
lead_ids = vals.get('lead_ids', [])
|
||||
user_ids = vals.get('user_ids', False)
|
||||
team_id = vals.get('section_id', False)
|
||||
return lead.convert_opportunity(cr, uid, lead_ids, partner_id, user_ids, team_id, context=context)
|
||||
for lead_id in lead_ids:
|
||||
if context.get('mass_convert'):
|
||||
partner_id = partner_ids_map.get(lead_id, False)
|
||||
# FIXME: cannot pass user_ids as the salesman allocation only works in batch
|
||||
res = lead.convert_opportunity(cr, uid, [lead_id], partner_id, [], team_id, context=context)
|
||||
# FIXME: must perform salesman allocation in batch separately here
|
||||
user_ids = vals.get('user_ids', False)
|
||||
if user_ids:
|
||||
lead.allocate_salesman(cr, uid, lead_ids, user_ids, team_id=team_id, context=context)
|
||||
return res
|
||||
|
||||
def _merge_opportunity(self, cr, uid, ids, opportunity_ids, action='merge', context=None):
|
||||
if context is None:
|
||||
@@ -136,7 +148,6 @@ class crm_lead2opportunity_partner(osv.osv_memory):
|
||||
"""
|
||||
if not context:
|
||||
context = {}
|
||||
|
||||
lead = self.pool.get('crm.lead')
|
||||
lead_ids = context.get('active_ids', [])
|
||||
data = self.browse(cr, uid, ids, context=context)[0]
|
||||
|
||||
@@ -108,6 +108,8 @@ class crm_lead2partner(osv.osv_memory):
|
||||
data = self.browse(cr, uid, ids, context=context)[0]
|
||||
partner_id = data.partner_id and data.partner_id.id or False
|
||||
partner_ids = lead.convert_partner(cr, uid, lead_ids, data.action, partner_id, context=context)
|
||||
if context.get('mass_convert'):
|
||||
return partner_ids
|
||||
return partner_ids[lead_ids[0]]
|
||||
|
||||
def make_partner(self, cr, uid, ids, context=None):
|
||||
|
||||
Reference in New Issue
Block a user