[WIP] redirect to the right view (opp or lead)

improve documentation and code style

bzr revid: abo@openerp.com-20121120181333-ho2zu27q1qs2hoe5
This commit is contained in:
Antonin Bourguignon 2012-11-20 19:13:33 +01:00
parent 3dba2e5586
commit 4e64f8e96f
2 changed files with 32 additions and 20 deletions

View File

@ -445,16 +445,22 @@ class crm_lead(base_stage, format_address, osv.osv):
return data
def _merge_find_oldest(self, cr, uid, ids, context=None):
"""
Return the oldest lead found among ids.
:param list ids: list of ids of the leads to inspect
:return int id: the id of the oldest of the leads
"""
if context is None:
context = {}
#TOCHECK: where pass 'convert' in context ?
if context.get('convert'):
ids = list(set(ids) - set(context.get('lead_ids', False)) )
#search opportunities order by create date
opportunity_ids = self.search(cr, uid, [('id', 'in', ids)], order='create_date' , context=context)
oldest_id = opportunity_ids[0]
return self.browse(cr, uid, oldest_id, context=context)
if context.get('convert'):
ids = list(set(ids) - set(context.get('lead_ids', [])))
# Search opportunities order by create date
opportunity_ids = self.search(cr, uid, [('id', 'in', ids)], order='create_date', context=context)
oldest_opp_id = opportunity_ids[0]
return self.browse(cr, uid, oldest_opp_id, context=context)
def _mail_body(self, cr, uid, lead, fields, title=False, context=None):
body = []
@ -537,8 +543,12 @@ class crm_lead(base_stage, format_address, osv.osv):
def merge_opportunity(self, cr, uid, ids, context=None):
"""
To merge opportunities
:param ids: list of opportunities ids to merge
Different cases of merge:
- merge leads together = 1 new lead
- merge at least 1 opp with anything else (lead or opp) = 1 new opp
:param ids: list of leads/opportunities ids to merge
:return int id: id of the resulting lead/opp
"""
if context is None: context = {}

View File

@ -22,7 +22,7 @@ from tools.translate import _
class crm_merge_opportunity(osv.osv_memory):
"""
Merge two opportunities together.
Merge opportunities together.
If we're talking about opportunities, it's just because it makes more sense
to merge opps than leads, because the leads are more ephemeral objects.
But since opportunities are leads, it's also possible to merge leads
@ -37,23 +37,25 @@ class crm_merge_opportunity(osv.osv_memory):
}
def action_merge(self, cr, uid, ids, context=None):
"""
Different cases of merge:
- merge 2 leads together = 1 new lead
- merge 2 opps together = 1 new opp
- merge 1 lead and 1 opp together = 1 new opp
"""
if context is None:
context = {}
lead = self.pool.get('crm.lead')
lead_obj = self.pool.get('crm.lead')
wizard = self.browse(cr, uid, ids[0], context=context)
opportunity2merge_ids = wizard.opportunity_ids
#TODO: why is this passed through the context, and not as an argument ? It looks dirty...
#TODO: why is this passed through the context ?
context['lead_ids'] = [opportunity2merge_ids[0].id]
merge_id = lead.merge_opportunity(cr, uid, [x.id for x in opportunity2merge_ids], context=context)
return lead.redirect_opportunity_view(cr, uid, merge_id, context=context)
merge_id = lead_obj.merge_opportunity(cr, uid, [x.id for x in opportunity2merge_ids], context=context)
# The newly created lead might be a lead or an opp: redirect toward the right view
merge_result = lead_obj.browse(cr, uid, merge_id, context=context)
if merge_result.type == 'opportunity':
return lead_obj.redirect_opportunity_view(cr, uid, merge_id, context=context)
else:
return lead_obj.redirect_lead_view(cr, uid, merge_id, context=context)
def default_get(self, cr, uid, fields, context=None):
"""