attachment.write(values)
return True
- def merge_opportunity(self, cr, uid, ids, context=None):
+ def merge_opportunity(self, cr, uid, ids, user_id=False, section_id=False, context=None):
"""
Different cases of merge:
- merge leads together = 1 new lead
fields = list(CRM_LEAD_FIELDS_TO_MERGE)
merged_data = self._merge_data(cr, uid, ids, highest, fields, context=context)
+ if user_id:
+ merged_data['user_id'] = user_id
+ if section_id:
+ merged_data['section_id'] = section_id
+
# Merge messages and attachements into the first opportunity
self._merge_opportunity_history(cr, uid, highest.id, tail_opportunities, context=context)
self._merge_opportunity_attachments(cr, uid, highest.id, tail_opportunities, context=context)
('merge', 'Merge with existing opportunities')
], 'Conversion Action', required=True),
'opportunity_ids': fields.many2many('crm.lead', string='Opportunities'),
+ 'user_id': fields.many2one('res.users', 'Salesperson', select=True),
+ 'section_id': fields.many2one('crm.case.section', 'Sales Team', select=True),
}
def default_get(self, cr, uid, fields, context=None):
res.update({'name' : len(tomerge) >= 2 and 'merge' or 'convert'})
if 'opportunity_ids' in fields and len(tomerge) >= 2:
res.update({'opportunity_ids': list(tomerge)})
-
+ if lead.user_id:
+ res.update({'user_id': lead.user_id.id})
+ if lead.section_id:
+ res.update({'section_id': lead.section_id.id})
return res
+ def on_change_user(self, cr, uid, ids, user_id, section_id, context=None):
+ """ When changing the user, also set a section_id or restrict section id
+ to the ones user_id is member of. """
+ if user_id:
+ if section_id:
+ user_in_section = self.pool.get('crm.case.section').search(cr, uid, [('id', '=', section_id), '|', ('user_id', '=', user_id), ('member_ids', '=', user_id)], context=context, count=True)
+ else:
+ user_in_section = False
+ if not user_in_section:
+ section_id = False
+ section_ids = self.pool.get('crm.case.section').search(cr, uid, ['|', ('user_id', '=', user_id), ('member_ids', '=', user_id)], context=context)
+ if section_ids:
+ section_id = section_ids[0]
+ return {'value': {'section_id': section_id}}
+
def view_init(self, cr, uid, fields, context=None):
"""
Check some preconditions before the wizard executes.
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, context=context)
+ lead_id = self.pool.get('crm.lead').merge_opportunity(cr, uid, opp_ids, w.user_id.id, w.section_id.id, 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)
+ self._convert_opportunity(cr, uid, ids, {'lead_ids': lead_ids, 'user_ids': [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}, context=context)
+ self._convert_opportunity(cr, uid, ids, {'lead_ids': lead_ids, 'user_ids': [w.user_id.id], 'section_id': w.section_id.id}, context=context)
return self.pool.get('crm.lead').redirect_opportunity_view(cr, uid, lead_ids[0], context=context)
<group name="name">
<field name="name" class="oe_inline"/>
</group>
+ <group string="Assign opportunities to">
+ <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="Opportunities">
<field name="opportunity_ids" attrs="{'invisible': [('name', '!=', 'merge')]}" nolabel="1">
<tree>
attrs="{'required': [('action', '=', 'exist')], 'invisible':[('action','!=','exist')]}"
class="oe_inline"/>
</group>
+ <group string="Assign opportunities to" attrs="{'invisible': [('name', '=', '')]}">
+ <field name="section_id" groups="base.group_multi_salesteams"/>
+ <field name="user_ids" widget="many2many_tags"/>
+ </group>
<group string="Select Opportunities" attrs="{'invisible': [('name', '!=', 'merge')]}">
<field name="opportunity_ids" colspan="4" nolabel="1" attrs="{'invisible': [('name', '=', 'convert')]}">
<tree>
</tree>
</field>
</group>
-
- <group string="Assign opportunities to" attrs="{'invisible': [('name', '=', '')]}">
- <field name="section_id" groups="base.group_multi_salesteams"/>
- <field name="user_ids" widget="many2many_tags"/>
- </group>
-
<footer>
<button name="mass_convert" string="Convert to Opportunities" type="object" class="oe_highlight"/>
or
_description = 'Merge opportunities'
_columns = {
'opportunity_ids': fields.many2many('crm.lead', rel='merge_opportunity_rel', id1='merge_id', id2='opportunity_id', string='Leads/Opportunities'),
+ 'user_id': fields.many2one('res.users', 'Salesperson', select=True),
+ 'section_id': fields.many2one('crm.case.section', 'Sales Team', select=True),
}
def action_merge(self, cr, uid, ids, context=None):
#TODO: why is this passed through the context ?
context['lead_ids'] = [opportunity2merge_ids[0].id]
- merge_id = lead_obj.merge_opportunity(cr, uid, [x.id for x in opportunity2merge_ids], context=context)
+ merge_id = lead_obj.merge_opportunity(cr, uid, [x.id for x in opportunity2merge_ids], wizard.user_id.id, wizard.section_id.id, 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)
return res
+ def on_change_user(self, cr, uid, ids, user_id, section_id, context=None):
+ """ When changing the user, also set a section_id or restrict section id
+ to the ones user_id is member of. """
+ if user_id:
+ if section_id:
+ user_in_section = self.pool.get('crm.case.section').search(cr, uid, [('id', '=', section_id), '|', ('user_id', '=', user_id), ('member_ids', '=', user_id)], context=context, count=True)
+ else:
+ user_in_section = False
+ if not user_in_section:
+ section_id = False
+ section_ids = self.pool.get('crm.case.section').search(cr, uid, ['|', ('user_id', '=', user_id), ('member_ids', '=', user_id)], context=context)
+ if section_ids:
+ section_id = section_ids[0]
+ return {'value': {'section_id': section_id}}
+
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
<field name="model">crm.merge.opportunity</field>
<field name="arch" type="xml">
<form string="Merge Leads/Opportunities" version="7.0">
- <separator string="Select Leads/Opportunities"/>
- <field name="opportunity_ids">
- <tree>
- <field name="create_date"/>
- <field name="name"/>
- <field name="type"/>
- <field name="contact_name"/>
- <field name="email_from"/>
- <field name="phone"/>
- <field name="stage_id"/>
- <field name="user_id"/>
- <field name="section_id" groups="base.group_multi_salesteams"/>
- </tree>
- </field>
+ <group string="Assign opportunities to">
+ <field name="user_id" class="oe_inline" on_change="on_change_user(user_id, context)"/>
+ <field name="section_id" class="oe_inline"/>
+ </group>
+ <group string="Select Leads/Opportunities">
+ <field name="opportunity_ids" nolabel="1">
+ <tree>
+ <field name="create_date"/>
+ <field name="name"/>
+ <field name="type"/>
+ <field name="contact_name"/>
+ <field name="email_from"/>
+ <field name="phone"/>
+ <field name="stage_id"/>
+ <field name="user_id"/>
+ <field name="section_id" groups="base.group_multi_salesteams"/>
+ </tree>
+ </field>
+ </group>
<footer>
<button name="action_merge" type="object" string="Merge" class="oe_highlight"/>
or