From 822d1b3d1310280a440366fdc6432ae6c02bdedc Mon Sep 17 00:00:00 2001 From: Antony Lesuisse Date: Fri, 1 Feb 2013 11:47:28 +0100 Subject: [PATCH 1/8] crm merge fix bzr revid: al@openerp.com-20130201104728-35rh2flvyjq8pxkn --- addons/crm/wizard/crm_lead_to_opportunity.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/addons/crm/wizard/crm_lead_to_opportunity.py b/addons/crm/wizard/crm_lead_to_opportunity.py index e7129c98d6c..acff3e7b877 100644 --- a/addons/crm/wizard/crm_lead_to_opportunity.py +++ b/addons/crm/wizard/crm_lead_to_opportunity.py @@ -62,15 +62,11 @@ class crm_lead2opportunity_partner(osv.osv_memory): ids = [] 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), ('type', '=', 'opportunity'), '!', ('state', 'in', ['done', 'cancel'])]) + ids = lead_obj.search(cr, uid, [('partner_id', '=', partner_id), ('type', '=', 'opportunity')]) if ids: opportunities.append(ids[0]) - if not partner_id: - if email: - # Find email of existing opportunity matching the email_from of the lead - cr.execute("""select id from crm_lead where type='opportunity' and - substring(email_from from '([^ ,<@]+@[^> ,]+)') in (%s)""" % (','.join(email))) - ids = map(lambda x:x[0], cr.fetchall()) + if email: + ids = lead_obj.search(cr, uid, [('email', 'ilike', email), ('type', '=', 'opportunity')]) if ids: opportunities.append(ids[0]) From ef30f3a6a808849fe241a49683c0f0a97ab7a635 Mon Sep 17 00:00:00 2001 From: hacker on test server <> Date: Fri, 1 Feb 2013 15:18:11 +0100 Subject: [PATCH 2/8] [FIX]Convert to opportunities bzr revid: hacker_on_test_server-20130201141811-s3byg8g19mya0fuk --- addons/crm/crm_lead_view.xml | 1 + addons/crm/wizard/crm_lead_to_opportunity.py | 51 +++++++++---------- .../wizard/crm_lead_to_opportunity_view.xml | 18 +++++-- 3 files changed, 38 insertions(+), 32 deletions(-) diff --git a/addons/crm/crm_lead_view.xml b/addons/crm/crm_lead_view.xml index 3d7bd45a209..093a6f43094 100644 --- a/addons/crm/crm_lead_view.xml +++ b/addons/crm/crm_lead_view.xml @@ -219,6 +219,7 @@ + diff --git a/addons/crm/wizard/crm_lead_to_opportunity.py b/addons/crm/wizard/crm_lead_to_opportunity.py index acff3e7b877..48603e6beff 100644 --- a/addons/crm/wizard/crm_lead_to_opportunity.py +++ b/addons/crm/wizard/crm_lead_to_opportunity.py @@ -46,38 +46,35 @@ class crm_lead2opportunity_partner(osv.osv_memory): lead_obj = self.pool.get('crm.lead') res = super(crm_lead2opportunity_partner, self).default_get(cr, uid, fields, context=context) - opportunities = res.get('opportunity_ids') or [] - partner_id = False - email = False - for lead in lead_obj.browse(cr, uid, opportunities, context=context): - partner_id = lead.partner_id and lead.partner_id.id or False + if context.get('active_id'): + tomerge = set([int(context['active_id'])]) + + email = False + partner_id = res.get('partner_id') + lead = lead_obj.browse(cr, uid, int(context['active_id']), context=context) #TOFIX: use mail.mail_message.to_mail email = re.findall(r'([^ ,<@]+@[^> ,]+)', lead.email_from or '') - email = map(lambda x: "'" + x + "'", email) + email = email[0] - if not partner_id and res.get('partner_id'): - partner_id = res.get('partner_id') + 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), ('type', '=', 'opportunity')]) + for id in ids: + tomerge.add(id) + if email: + ids = lead_obj.search(cr, uid, [('email_from', 'ilike', email), ('type', '=', 'opportunity')]) + for id in ids: + tomerge.add(id) - ids = [] - 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), ('type', '=', 'opportunity')]) - if ids: - opportunities.append(ids[0]) - if email: - ids = lead_obj.search(cr, uid, [('email', 'ilike', email), ('type', '=', 'opportunity')]) - if ids: - opportunities.append(ids[0]) - - if 'action' in fields: - res.update({'action' : partner_id and 'exist' or 'create'}) - if 'partner_id' in fields: - res.update({'partner_id' : partner_id}) - if 'name' in fields: - res.update({'name' : ids and 'merge' or 'convert'}) - if 'opportunity_ids' in fields: - res.update({'opportunity_ids': opportunities}) + if 'action' in fields: + res.update({'action' : partner_id and 'exist' or 'create'}) + if 'partner_id' in fields: + res.update({'partner_id' : partner_id}) + if 'name' in fields: + res.update({'name' : ids and 'merge' or 'convert'}) + if 'opportunity_ids' in fields and len(tomerge) >= 2: + res.update({'opportunity_ids': list(tomerge)}) return res diff --git a/addons/crm/wizard/crm_lead_to_opportunity_view.xml b/addons/crm/wizard/crm_lead_to_opportunity_view.xml index 1a7bd687a94..6e97dec9a33 100644 --- a/addons/crm/wizard/crm_lead_to_opportunity_view.xml +++ b/addons/crm/wizard/crm_lead_to_opportunity_view.xml @@ -9,12 +9,20 @@
- + + + - - - - + + + + + + + + + + From 91954d029f38d6a7e000fca352f0e4eefab49b3d Mon Sep 17 00:00:00 2001 From: hacker on test server <> Date: Fri, 1 Feb 2013 17:18:50 +0100 Subject: [PATCH 3/8] [FIX] crm leads merge views and action = merge not well placed bzr revid: hacker_on_test_server-20130201161850-m9xnp901la968ogo --- addons/crm/wizard/crm_lead_to_opportunity.py | 7 ++++--- addons/crm/wizard/crm_lead_to_opportunity_view.xml | 2 +- addons/crm/wizard/crm_merge_opportunities_view.xml | 10 +++++++--- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/addons/crm/wizard/crm_lead_to_opportunity.py b/addons/crm/wizard/crm_lead_to_opportunity.py index 48603e6beff..9ae0153c7dd 100644 --- a/addons/crm/wizard/crm_lead_to_opportunity.py +++ b/addons/crm/wizard/crm_lead_to_opportunity.py @@ -108,7 +108,7 @@ class crm_lead2opportunity_partner(osv.osv_memory): lead.allocate_salesman(cr, uid, lead_ids, user_ids, team_id=team_id, context=context) return res - def _merge_opportunity(self, cr, uid, ids, opportunity_ids, action='merge', context=None): + def _merge_opportunity(self, cr, uid, ids, opportunity_ids, context=None): if context is None: context = {} res = False @@ -117,7 +117,7 @@ class crm_lead2opportunity_partner(osv.osv_memory): # merged into the first opportunity (and the rest deleted) opportunity_ids = [o.id for o in opportunity_ids] lead_ids = context.get('active_ids', []) - if action == 'merge' and lead_ids and opportunity_ids: + if lead_ids and opportunity_ids: # Add the leads in the to-merge list, next to other opps # (the fact that they're passed in context['lead_ids'] means that # they cannot be selected to contain the result of the merge. @@ -137,7 +137,8 @@ class crm_lead2opportunity_partner(osv.osv_memory): lead_ids = context.get('active_ids', []) data = self.browse(cr, uid, ids, context=context)[0] self._convert_opportunity(cr, uid, ids, {'lead_ids': lead_ids}, context=context) - self._merge_opportunity(cr, uid, ids, data.opportunity_ids, data.name, context=context) + if data.name == 'merge': + self._merge_opportunity(cr, uid, ids, data.opportunity_ids, context=context) return 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 6e97dec9a33..0459b3093dd 100644 --- a/addons/crm/wizard/crm_lead_to_opportunity_view.xml +++ b/addons/crm/wizard/crm_lead_to_opportunity_view.xml @@ -14,7 +14,7 @@ - + diff --git a/addons/crm/wizard/crm_merge_opportunities_view.xml b/addons/crm/wizard/crm_merge_opportunities_view.xml index 4b035200737..6555e5b8f28 100644 --- a/addons/crm/wizard/crm_merge_opportunities_view.xml +++ b/addons/crm/wizard/crm_merge_opportunities_view.xml @@ -11,10 +11,14 @@ + - - - + + + + + +