Skip to content

Commit

Permalink
[MERGE] trunk-bug-1065751-abo: fix the double partner creation in lea…
Browse files Browse the repository at this point in the history
…d2opportunity (introduced in revno 7251.1.122 revid:odo@openerp.com-20120823200629-1m1eym62l7aabzgl)

lp bug: https://launchpad.net/bugs/1065751 fixed

bzr revid: abo@openerp.com-20121107170532-nhrxnm0rv58osk4m
  • Loading branch information
Antonin Bourguignon committed Nov 7, 2012
2 parents a963bd0 + 664e05b commit a6d3dfb
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 18 deletions.
6 changes: 2 additions & 4 deletions addons/crm/crm_lead.py
Original file line number Diff line number Diff line change
Expand Up @@ -610,9 +610,9 @@ def _convert_opportunity_data(self, cr, uid, lead, customer, section_id=False, c
}

def convert_opportunity(self, cr, uid, ids, partner_id, user_ids=False, section_id=False, context=None):
partner = self.pool.get('res.partner')
customer = False
if partner_id:
partner = self.pool.get('res.partner')
customer = partner.browse(cr, uid, partner_id, context=context)
for lead in self.browse(cr, uid, ids, context=context):
if lead.state in ('done', 'cancel'):
Expand Down Expand Up @@ -676,19 +676,17 @@ def _lead_set_partner(self, cr, uid, lead, partner_id, context=None):

def convert_partner(self, cr, uid, ids, action='create', partner_id=False, context=None):
"""
This function convert partner based on action.
Convert partner based on action.
if action is 'create', create new partner with contact and assign lead to new partner_id.
otherwise assign lead to specified partner_id
"""
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._create_lead_partner(cr, uid, lead, context)
partner_id = force_partner_id or self._create_lead_partner(cr, uid, lead, context=context)
self._lead_set_partner(cr, uid, lead, partner_id, context=context)
partner_ids[lead.id] = partner_id
return partner_ids
Expand Down
13 changes: 10 additions & 3 deletions addons/crm/wizard/crm_lead_to_opportunity.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,12 +175,19 @@ def default_get(self, cr, uid, fields, context=None):
return res

def _convert_opportunity(self, cr, uid, ids, vals, context=None):
"""
When "massively" (more than one at a time) converting leads to
opportunities, check the salesteam_id and salesmen_ids and update
the values before calling super.
"""
if context is None:
context = {}
data = self.browse(cr, uid, ids, context=context)[0]
salesteam_id = data.section_id and data.section_id.id or False
salesman = []
salesmen_ids = []
if data.user_ids:
salesman = [x.id for x in data.user_ids]
vals.update({'user_ids': salesman, 'section_id': salesteam_id})
salesmen_ids = [x.id for x in data.user_ids]
vals.update({'user_ids': salesmen_ids, 'section_id': salesteam_id})
return super(crm_lead2opportunity_mass_convert, self)._convert_opportunity(cr, uid, ids, vals, context=context)

def mass_convert(self, cr, uid, ids, context=None):
Expand Down
19 changes: 8 additions & 11 deletions addons/crm/wizard/crm_lead_to_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class crm_lead2partner(osv.osv_memory):
}
def view_init(self, cr, uid, fields, context=None):
"""
This function checks for precondition before wizard executes
Check for precondition before wizard executes.
"""
if context is None:
context = {}
Expand Down Expand Up @@ -69,22 +69,19 @@ def _select_partner(self, cr, uid, context=None):
return partner_id

def default_get(self, cr, uid, fields, context=None):
"""
This function gets default values
"""
res = super(crm_lead2partner, self).default_get(cr, uid, fields, context=context)
res = super(crm_lead2partner, self).default_get(cr, uid, fields, context=context)
partner_id = self._select_partner(cr, uid, context=context)

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 open_create_partner(self, cr, uid, ids, context=None):
"""
This function Opens form of create partner.
Open form of create partner.
"""
view_obj = self.pool.get('ir.ui.view')
view_id = view_obj.search(cr, uid, [('model', '=', self._name), \
Expand All @@ -101,21 +98,21 @@ def open_create_partner(self, cr, uid, ids, context=None):

def _create_partner(self, cr, uid, ids, context=None):
"""
This function Creates partner based on action.
Create partner based on action.
"""
if context is None:
context = {}
lead = self.pool.get('crm.lead')
lead_ids = context and context.get('active_ids') or []
lead_ids = context.get('active_ids', [])
data = self.browse(cr, uid, ids, context=context)[0]
partner_id = data.partner_id and data.partner_id.id or False
return lead.convert_partner(cr, uid, lead_ids, data.action, partner_id, context=context)

def make_partner(self, cr, uid, ids, context=None):
"""
This function Makes partner based on action.
Make a partner based on action.
Only called from form view, so only meant to convert one lead at a time.
"""
# Only called from Form view, so only meant to convert one Lead.
lead_id = context and context.get('active_id') or False
partner_ids_map = self._create_partner(cr, uid, ids, context=context)
return self.pool.get('res.partner').redirect_partner_form(cr, uid, partner_ids_map.get(lead_id, False), context=context)
Expand Down

0 comments on commit a6d3dfb

Please sign in to comment.