From 9d2cf73253089464ec06c23e029ea74be5655a35 Mon Sep 17 00:00:00 2001 From: "dle@openerp.com" <> Date: Wed, 17 Apr 2013 18:17:03 +0200 Subject: [PATCH] [FIX]crm: lead/opp convert/opp wizard: Add salesperson and salesteam in wizard form bzr revid: dle@openerp.com-20130417161703-z3id6hb20c9pceho --- addons/crm/crm_lead.py | 7 +++- addons/crm/wizard/crm_lead_to_opportunity.py | 28 +++++++++++++--- .../wizard/crm_lead_to_opportunity_view.xml | 14 ++++---- addons/crm/wizard/crm_merge_opportunities.py | 19 ++++++++++- .../wizard/crm_merge_opportunities_view.xml | 33 +++++++++++-------- 5 files changed, 75 insertions(+), 26 deletions(-) diff --git a/addons/crm/crm_lead.py b/addons/crm/crm_lead.py index 2361f12d61b..b8e8b58aaf4 100644 --- a/addons/crm/crm_lead.py +++ b/addons/crm/crm_lead.py @@ -628,7 +628,7 @@ class crm_lead(base_stage, format_address, osv.osv): 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 @@ -662,6 +662,11 @@ class crm_lead(base_stage, format_address, osv.osv): 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) diff --git a/addons/crm/wizard/crm_lead_to_opportunity.py b/addons/crm/wizard/crm_lead_to_opportunity.py index e67b7c0c7be..ca99de80779 100644 --- a/addons/crm/wizard/crm_lead_to_opportunity.py +++ b/addons/crm/wizard/crm_lead_to_opportunity.py @@ -35,6 +35,8 @@ class crm_lead2opportunity_partner(osv.osv_memory): ('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): @@ -74,9 +76,27 @@ class crm_lead2opportunity_partner(osv.osv_memory): 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. @@ -118,15 +138,15 @@ class crm_lead2opportunity_partner(osv.osv_memory): 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) diff --git a/addons/crm/wizard/crm_lead_to_opportunity_view.xml b/addons/crm/wizard/crm_lead_to_opportunity_view.xml index 4093df910d0..e06ff091960 100644 --- a/addons/crm/wizard/crm_lead_to_opportunity_view.xml +++ b/addons/crm/wizard/crm_lead_to_opportunity_view.xml @@ -10,6 +10,10 @@ + + + + @@ -56,6 +60,10 @@ attrs="{'required': [('action', '=', 'exist')], 'invisible':[('action','!=','exist')]}" class="oe_inline"/> + + + + @@ -72,12 +80,6 @@ - - - - - -