A. Fonctionnal Side :
The Reason for this change, is that I want converting to opportunity button always work with this conversion options :
Conversion Action : Convert to opportunity
Action : Create Partner.
So for me there is no need to open a wizard so as to select these options, therefore, I decided to change the button's type to "object" wich does always the conversion with the options above.
B. Technical Side :
I changed the type of the button "CONVERT TO OPPORTUNITY" from action to object on the crm_lead_view.xml, and on the crm_lead.py, I added the action_apply_directly method, associeted with my new button of type "object",
Here is The Method :
def action_apply_directly(self, cr, uid, ids, context=None):
"""
Convert lead to opportunity and open
the freshly created opportunity view.
"""
res = self.pool.get('crm.lead2opportunity.partner').action_apply(cr, uid, ids)
return res
Si I just called the action_apply method on the "crm.lead2opportunity.partner" object, wich I updated like this :
def action_apply(self, cr, uid, ids, context=None):
"""
Convert lead to opportunity or merge lead and opportunity and open
the freshly created opportunity view.
"""
if context is None:
context = {}
# w = self.pool.get('crm.lead').browse(cr, uid, ids, context=context)[0]
# lead_ids = [o.id for o in w]
# if w.name == 'merge':
# lead_id = self.pool.get('crm.lead').merge_opportunity(cr, uid, opp_ids, context=context)
# lead_ids = [lead_id]
# lead = self.pool.get('crm.lead').read(cr, uid, lead_id, ['type'], context=context)
# if lead['type'] == "lead":
# context.update({'active_ids': lead_ids})
# self._convert_opportunity(cr, uid, ids, {'lead_ids': lead_ids}, context=context)
lead_ids = context.get('active_ids', [])
self._convert_opportunity_wiz(cr, uid, ids, {'lead_ids': lead_ids}, context=context)
return self.pool.get('crm.lead').redirect_opportunity_view(cr, uid, lead_ids[0], context=context)
I commented all the treatments related to merge opportunities option, and keep only the convert to opportunity option treatment only.
When I run click on the button, it shows me the following error :
"/opt/openerp/server/openerp/addons/crm/wizard/crm_lead_to_opportunity.py", line 134, in action_apply return self.pool.get('crm.lead').redirect_opportunity_view(cr, uid, lead_ids[0], context=context) IndexError: list index out of range
I think There is something wrong with : lead_ids = context.get('active_ids', []), so that it doesn't give data to lead_ids list.
Could you please give me a hand. I'm here if you want more explanations.