[IMP]: crm: Converting lead to opportunity wizard will prompt for option that will either convert to opportunity or merge with existing opportunity

bzr revid: rpa@tinyerp.com-20100729111522-jcds5mrqcgmxx8ci
This commit is contained in:
rpa (Open ERP)
2010-07-29 16:45:22 +05:30
parent 8673e42f72
commit 22da750884
5 changed files with 90 additions and 8 deletions
+3 -2
View File
@@ -236,12 +236,13 @@ class crm_lead(osv.osv, crm_case):
context.update({'active_ids': ids})
data_obj = self.pool.get('ir.model.data')
data_id = data_obj._get_id(cr, uid, 'crm', 'view_crm_lead2opportunity_create')
data_id = data_obj._get_id(cr, uid, 'crm', 'view_crm_lead2opportunity_action')
value = {}
view_id = False
if data_id:
view_id = data_obj.browse(cr, uid, data_id, context=context).res_id
for case in self.browse(cr, uid, ids):
context.update({'active_id': case.id})
if not case.partner_id:
@@ -267,7 +268,7 @@ class crm_lead(osv.osv, crm_case):
'name': _('Create Opportunity'),
'view_type': 'form',
'view_mode': 'form,tree',
'res_model': 'crm.lead2opportunity',
'res_model': 'crm.lead2opportunity.action',
'view_id': False,
'context': context,
'views': [(view_id, 'form')],
+1 -1
View File
@@ -35,7 +35,7 @@
<field name="date_action"/>
<field name="title_action"/>
<field name="priority" string="Priority"/>
<button string="Merge with Other Opportunity"
<button string="Merge with other Opportunity"
name="%(merge_opportunity_act)d" icon="gtk-add" type="action" />
<newline/>
<field name="type" invisible="1"/>
+65 -2
View File
@@ -222,7 +222,7 @@ class crm_lead2opportunity_partner(osv.osv_memory):
res = mod_obj.read(cr, uid, result, ['res_id'])
value = {}
data_obj = self.pool.get('ir.model.data')
data_id = data_obj._get_id(cr, uid, 'crm', 'view_crm_lead2opportunity_create')
data_id = data_obj._get_id(cr, uid, 'crm', 'view_crm_lead2opportunity_action')
view_id = False
if data_id:
view_id = data_obj.browse(cr, uid, data_id, context=context).res_id
@@ -232,7 +232,7 @@ class crm_lead2opportunity_partner(osv.osv_memory):
'name': _('Create Opportunity'),
'view_type': 'form',
'view_mode': 'form,tree',
'res_model': 'crm.lead2opportunity',
'res_model': 'crm.lead2opportunity.action',
'view_id': False,
'context': context,
'views': [(view_id, 'form')],
@@ -297,5 +297,68 @@ Leads Could not convert into Opportunity"))
crm_lead2opportunity_partner()
class crm_lead2opportunity_action(osv.osv_memory):
'''
Merge with Existing Opportunity or Convert to Opportunity
'''
_name = 'crm.lead2opportunity.action'
_description = 'Convert/Merge Opportunity'
_columns = {
'name': fields.selection([('convert', 'Convert to Opportunity'), ('merge', 'Merge with existing Opportunity')],'Select Action', required=True),
}
_defaults = {
'name': 'convert',
}
def do_action(self, cr, uid, ids, context=None):
"""
This function opens form according to selected Action
@param self: The object pointer
@param cr: the current row, from the database cursor,
@param uid: the current user’s ID for security checks,
@param ids: List of Lead to Opportunity IDs
@param context: A standard dictionary for contextual values
@return : Dictionary value for Opportunity form
"""
value = {}
data_obj = self.pool.get('ir.model.data')
view_id = False
for this in self.browse(cr, uid, ids, context=context):
if this.name == 'convert':
data_id = data_obj._get_id(cr, uid, 'crm', 'view_crm_lead2opportunity_create')
if data_id:
view_id = data_obj.browse(cr, uid, data_id, context=context).res_id
value = {
'name': _('Create Opportunity'),
'view_type': 'form',
'view_mode': 'form,tree',
'res_model': 'crm.lead2opportunity',
'view_id': False,
'context': context,
'views': [(view_id, 'form')],
'type': 'ir.actions.act_window',
'target': 'new',
}
elif this.name == 'merge':
data_id = data_obj._get_id(cr, uid, 'crm', 'merge_opportunity_form')
if data_id:
view_id = data_obj.browse(cr, uid, data_id, context=context).res_id
value = {
'name': _('Merge with Existing Opportunity'),
'view_type': 'form',
'view_mode': 'form,tree',
'res_model': 'crm.merge.opportunity',
'view_id': False,
'context': context,
'views': [(view_id, 'form')],
'type': 'ir.actions.act_window',
'target': 'new',
}
return value
crm_lead2opportunity_action()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
@@ -3,7 +3,7 @@
<!-- Lead to Opportunity view -->
<record id="view_crm_lead2opportunity_create" model="ir.ui.view">
<record id="view_crm_lead2opportunity_create" model="ir.ui.view">
<field name="name">crm.lead2opportunity.create</field>
<field name="model">crm.lead2opportunity</field>
<field name="type">form</field>
@@ -61,5 +61,25 @@
</field>
</record>
<record id="view_crm_lead2opportunity_action" model="ir.ui.view">
<field name="name">crm.lead2opportunity.action.form</field>
<field name="model">crm.lead2opportunity.action</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Select Action">
<separator string="Select Action" colspan="4" />
<label string="If you select Merge with existing Opportunity, the lead details(with the communication history) will be merged with existing Opportunity of Selected partner." colspan="4"/>
<newline/>
<field name="name" colspan="4"/>
<separator colspan="4" />
<group col="4" colspan="4">
<label colspan="2"/>
<button special="cancel" string="Cancel" icon="gtk-cancel"/>
<button name="do_action" string="Next" type="object" icon="gtk-go-forward"/>
</group>
</form>
</field>
</record>
</data>
</openerp>
@@ -42,8 +42,6 @@ class crm_merge_opportunity(osv.osv_memory):
if record_id:
opp_obj = self.pool.get('crm.lead')
opp = opp_obj.browse(cr, uid, record_id, context=context)
if opp.type != 'opportunity':
raise osv.except_osv(_('Warning!'), _('Can only perform this Operation for "Opportunities".'))
if not opp.partner_id:
raise osv.except_osv(_('Warning!'), _('Opportunity must have Partner assigned before merging with other Opportunity.'))
#Search for Opportunity for the same partner