[FIX] crm: lead_to_opp, do not force assignation in mass convert with deduplication (to prevent change the salesman of an existing opp), + fix get duplicated lead, now based on probability of stage instead of probability of the opp itself
bzr revid: dle@openerp.com-20140305164016-432vz5axo5l4wqko
This commit is contained in:
parent
f7058f9b64
commit
83a4374363
|
@ -46,12 +46,12 @@ class crm_lead2opportunity_partner(osv.osv_memory):
|
|||
results = []
|
||||
if partner_id:
|
||||
# Search for opportunities that have the same partner and that arent done or cancelled
|
||||
ids = lead_obj.search(cr, uid, [('partner_id', '=', partner_id), '|', ('probability', '=', False), ('probability', '<', '100')])
|
||||
ids = lead_obj.search(cr, uid, [('partner_id', '=', partner_id), '|', ('stage_id.probability', '=', False), ('stage_id.probability', '<', '100')])
|
||||
for id in ids:
|
||||
results.append(id)
|
||||
email = re.findall(r'([^ ,<@]+@[^> ,]+)', email or '')
|
||||
if email:
|
||||
ids = lead_obj.search(cr, uid, [('email_from', '=ilike', email[0]), '|', ('probability', '=', False), ('probability', '<', '100')])
|
||||
ids = lead_obj.search(cr, uid, [('email_from', '=ilike', email[0]), '|', ('stage_id.probability', '=', False), ('stage_id.probability', '<', '100')])
|
||||
for id in ids:
|
||||
results.append(id)
|
||||
return list(set(results))
|
||||
|
@ -124,14 +124,17 @@ class crm_lead2opportunity_partner(osv.osv_memory):
|
|||
lead_ids = vals.get('lead_ids', [])
|
||||
team_id = vals.get('section_id', False)
|
||||
data = self.browse(cr, uid, ids, context=context)[0]
|
||||
for lead_id in lead_ids:
|
||||
partner_id = self._create_partner(cr, uid, lead_id, data.action, data.partner_id.id, context=context)
|
||||
# FIXME: cannot pass user_ids as the salesman allocation only works in batch
|
||||
res = lead.convert_opportunity(cr, uid, [lead_id], partner_id, [], team_id, context=context)
|
||||
# FIXME: must perform salesman allocation in batch separately here
|
||||
leads = lead.browse(cr, uid, lead_ids, context=context)
|
||||
for lead_id in leads:
|
||||
partner_id = self._create_partner(cr, uid, lead_id.id, data.action, lead_id.partner_id.id, context=context)
|
||||
res = lead.convert_opportunity(cr, uid, [lead_id.id], partner_id, [], team_id, context=context)
|
||||
user_ids = vals.get('user_ids', False)
|
||||
if context.get('no_force_assignation'):
|
||||
leads_to_allocate = [lead_id.id for lead_id in leads if not lead_id.user_id]
|
||||
else:
|
||||
leads_to_allocate = lead_ids
|
||||
if user_ids:
|
||||
lead.allocate_salesman(cr, uid, lead_ids, user_ids, team_id=team_id, context=context)
|
||||
lead.allocate_salesman(cr, uid, leads_to_allocate, user_ids, team_id=team_id, context=context)
|
||||
return res
|
||||
|
||||
def action_apply(self, cr, uid, ids, context=None):
|
||||
|
@ -142,15 +145,19 @@ class crm_lead2opportunity_partner(osv.osv_memory):
|
|||
if context is None:
|
||||
context = {}
|
||||
|
||||
lead_obj = self.pool['crm.lead']
|
||||
|
||||
w = self.browse(cr, uid, ids, context=context)[0]
|
||||
opp_ids = [o.id for o in w.opportunity_ids]
|
||||
if w.name == 'merge':
|
||||
lead_id = self.pool.get('crm.lead').merge_opportunity(cr, uid, opp_ids, w.user_id.id, w.section_id.id, context=context)
|
||||
lead_id = lead_obj.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)
|
||||
lead = lead_obj.read(cr, uid, lead_id, ['type', 'user_id'], context=context)
|
||||
if lead['type'] == "lead":
|
||||
context.update({'active_ids': lead_ids})
|
||||
self._convert_opportunity(cr, uid, ids, {'lead_ids': lead_ids, 'user_ids': [w.user_id.id], 'section_id': w.section_id.id}, context=context)
|
||||
elif not context.get('no_force_assignation') or not lead['user_id']:
|
||||
lead_obj.write(cr, uid, lead_id, {'user_id': w.user_id.id, 'section_id': w.section_id.id}, context=context)
|
||||
else:
|
||||
lead_ids = context.get('active_ids', [])
|
||||
self._convert_opportunity(cr, uid, ids, {'lead_ids': lead_ids, 'user_ids': [w.user_id.id], 'section_id': w.section_id.id}, context=context)
|
||||
|
@ -184,11 +191,13 @@ class crm_lead2opportunity_mass_convert(osv.osv_memory):
|
|||
_columns = {
|
||||
'user_ids': fields.many2many('res.users', string='Salesmen'),
|
||||
'section_id': fields.many2one('crm.case.section', 'Sales Team'),
|
||||
'deduplicate': fields.boolean('Apply deduplication', help='Merge with existing leads/opportunities of each partner'),
|
||||
'deduplicate': fields.boolean('Apply deduplication', help='Merge with existing leads/opportunities of each partner'),
|
||||
'action': fields.selection([
|
||||
('each_exist_or_create', 'Use existing partner or create'),
|
||||
('nothing', 'Do not link to a customer')
|
||||
], 'Related Customer', required=True),
|
||||
# Uncomment me in trunk
|
||||
# 'force_assignation': fields.boolean('Force assignation', help='If unchecked, this will leave the salesman of duplicated opportunities'),
|
||||
}
|
||||
|
||||
_defaults = {
|
||||
|
@ -264,6 +273,10 @@ class crm_lead2opportunity_mass_convert(osv.osv_memory):
|
|||
active_ids = active_ids.difference(merged_lead_ids)
|
||||
active_ids = active_ids.union(remaining_lead_ids)
|
||||
ctx['active_ids'] = list(active_ids)
|
||||
# Remove me in trunk
|
||||
ctx['no_force_assignation'] = True
|
||||
# Uncomment me in trunk
|
||||
# ctx['no_force_assignation'] = not data.force_assignation
|
||||
return self.action_apply(cr, uid, ids, context=ctx)
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
|
|
@ -58,6 +58,8 @@
|
|||
<group string="Assign opportunities to">
|
||||
<field name="section_id" groups="base.group_multi_salesteams"/>
|
||||
<field name="user_ids" widget="many2many_tags"/>
|
||||
<!-- Uncomment me in trunk -->
|
||||
<!-- <field name="force_assignation" /> -->
|
||||
</group>
|
||||
<label for="opportunity_ids" string="Leads with existing duplicates (for information)" help="Leads that you selected that have duplicates. If the list is empty, it means that no duplicates were found" attrs="{'invisible': [('deduplicate', '=', False)]}"/>
|
||||
<group attrs="{'invisible': [('deduplicate', '=', False)]}">
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
<field name="arch" type="xml">
|
||||
<form string="Merge Leads/Opportunities" version="7.0">
|
||||
<group string="Assign opportunities to">
|
||||
<field name="user_id" class="oe_inline" on_change="on_change_user(user_id, context)"/>
|
||||
<field name="user_id" class="oe_inline" on_change="on_change_user(user_id, section_id, context)"/>
|
||||
<field name="section_id" class="oe_inline"/>
|
||||
</group>
|
||||
<group string="Select Leads/Opportunities">
|
||||
|
|
Loading…
Reference in New Issue