[ADD] Mass convert lead 2 opp

bzr revid: tfr@openerp.com-20110316143025-92c4khhhwjlc3c86
This commit is contained in:
Thibault Francois 2011-03-16 15:30:25 +01:00
parent f193393d01
commit 84fca70681
4 changed files with 107 additions and 5 deletions

View File

@ -130,6 +130,9 @@ Leads Could not convert into Opportunity"))
@return : View dictionary opening the Opportunity form view
"""
if not context:
context = {}
record_id = context and context.get('active_ids') or False
if not record_id:
return {'type': 'ir.actions.act_window_close'}
@ -154,7 +157,7 @@ Leads Could not convert into Opportunity"))
cr, uid, opportunity_view_tree, context=context).res_id
for lead in leads.browse(cr, uid, record_id, context=context):
if(lead.section_id):
if lead.section_id:
stage_ids = self.pool.get('crm.case.stage').search(cr, uid, [('type','=','opportunity'),('sequence','>=',1), ('section_ids','=', lead.section_id.id)])
else:
stage_ids = self.pool.get('crm.case.stage').search(cr, uid, [('type','=','opportunity'),('sequence','>=',1)])
@ -166,7 +169,8 @@ Leads Could not convert into Opportunity"))
partner_id = partner_ids and partner_ids[0] or data.partner_id.id
self._convert(cr, uid, ids, lead, partner_id, stage_ids, context=context)
if data.name == 'merge':
#If we convert in mass, don't merge if there is no other opportunity but no warning
if data.name == 'merge' and (len(data.opportunity_ids) > 1 or not context.get('mass-convert') ):
merge_obj = self.pool.get('crm.merge.opportunity')
self.write(cr, uid, ids, {'opportunity_ids' : [(6,0, [data.opportunity_ids[0].id])]}, context=context)
context.update({'lead_ids' : record_id})
@ -189,4 +193,66 @@ Leads Could not convert into Opportunity"))
crm_lead2opportunity_partner()
class crm_lead2opportunity_mass_convert(osv.osv_memory):
_name = 'crm.lead2opportunity.partner.mass'
_description = 'Mass Lead To Opportunity Partner'
_inherit = 'crm.lead2opportunity.partner'
_columns = {
'user_ids': fields.many2many('res.users', 'mass_convert_rel', 'user_id', 'wizard_id', 'Salesmans'),
'section_id': fields.many2one('crm.case.section', 'Sales Team'),
}
def mass_convert(self, cr, uid, ids, context=None):
lead_obj = self.pool.get('crm.lead')
if not context:
context = {}
active_ids = context.get('active_ids')
data = self.browse(cr, uid, ids, context=context)[0]
salesteam = data.section_id and data.section_id.id
if data.user_ids:
salesmans = map(lambda x : x.id, data.user_ids)
index = 0
else:
salesmans = False
for lead_id in active_ids:
value = {}
if salesteam:
value['section_id'] = salesteam
if salesmans:
value['user_id'] = salesmans[index]
index += 1
index = index < len(salesmans) and index or 0
if value:
lead_obj.write(cr, uid, [lead_id], value, context=context)
context['active_ids'] = [lead_id]
value = self.default_get(cr, uid, ['partner_id', 'opportunity_ids'], context=context)
value['opportunity_ids'] = [(6, 0, value['opportunity_ids'])]
self.write(cr, uid, ids, value, context=context)
self.action_apply(cr, uid, ids, context=context)
models_data = self.pool.get('ir.model.data')
result = models_data._get_id(cr, uid, 'crm', 'view_crm_case_opportunities_filter')
opportunity_view_search = models_data.browse(cr, uid, result, context=context).res_id
return {
'name': _('Opportunity'),
'view_type': 'form',
'view_mode': 'tree,form',
'res_model': 'crm.lead',
'domain': [('type', '=', 'opportunity'), ('id', 'in', active_ids)],
'type': 'ir.actions.act_window',
'search_view_id': opportunity_view_search,
}
crm_lead2opportunity_mass_convert()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -36,5 +36,42 @@
</field>
</record>
<record id="view_crm_lead2opportunity_partner_mass" model="ir.ui.view">
<field name="name">crm.lead2opportunity.partner.mass.form</field>
<field name="model">crm.lead2opportunity.partner.mass</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Convert to Opportunity">
<field name="action"/>
<field name="name" colspan="4"/>
<separator string="Assigned opportunities to" colspan="4" />
<field name="section_id" />
<group col="4" colspan="4">
<separator string="Select Salesman" colspan="4" />
</group>
<field name="user_ids" nolabel="1" colspan="4">
<tree>
<field name="name" />
</tree>
</field>
<separator string="" colspan="4" />
<group col="4" colspan="4">
<button special="cancel" string="Cancel" icon="gtk-cancel"/>
<button name="mass_convert" string="Convert into Opportunities" type="object" icon="gtk-ok"/>
</group>
</form>
</field>
</record>
<act_window id="action_crm_send_mass_convert"
multi="True"
key2="client_action_multi" name="Convert opportunities"
res_model="crm.lead2opportunity.partner.mass" src_model="crm.lead"
view_mode="form" target="new" view_type="form"
context="{'mass_convert' : True}"
view_id="view_crm_lead2opportunity_partner_mass"/>
</data>
</openerp>

View File

@ -71,7 +71,7 @@ class crm_lead2partner(osv.osv_memory):
contact_obj = self.pool.get('res.partner.address')
partner_id = False
data = context and context.get('active_ids', []) or []
data = list(context and context.get('active_ids', []) or [])
res = super(crm_lead2partner, self).default_get(cr, uid, fields, context=context)
for lead in lead_obj.browse(cr, uid, data, context=context):

View File

@ -64,7 +64,6 @@ class crm_merge_opportunity(osv.osv_memory):
lead_ids = context and context.pop('lead_ids', []) or []
if len(op_ids) <= 1:
raise osv.except_osv(_('Warning !'),_('Please select more than one opportunities.'))
@ -77,7 +76,7 @@ class crm_merge_opportunity(osv.osv_memory):
else:
first_opportunity = opportunities_list[0]
tail_opportunities = opportunities_list[1:]
data = {
'partner_id': self._get_first_not_null_id('partner_id', op_ids), # !!