Anto has proposed merging
lp:~openerp-dev/openobject-addons/trunk-improve_crm_leads_flux-abo into
lp:openobject-addons.
Requested reviews:
OpenERP Core Team (openerp)
For more details, see:
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-improve_crm_leads_flux-abo/+merge/133937
--
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-improve_crm_leads_flux-abo/+merge/133937
Your team OpenERP R&D Team is subscribed to branch
lp:~openerp-dev/openobject-addons/trunk-improve_crm_leads_flux-abo.
=== modified file 'crm/__openerp__.py'
--- crm/__openerp__.py 2012-10-26 17:09:04 +0000
+++ crm/__openerp__.py 2012-11-12 14:47:28 +0000
@@ -67,11 +67,9 @@
'security/crm_security.xml',
'security/ir.model.access.csv',
- 'wizard/crm_lead_to_partner_view.xml',
'wizard/crm_lead_to_opportunity_view.xml',
'wizard/crm_phonecall_to_phonecall_view.xml',
- 'wizard/crm_phonecall_to_partner_view.xml',
'wizard/crm_phonecall_to_opportunity_view.xml',
'wizard/crm_opportunity_to_phonecall_view.xml',
@@ -99,7 +97,6 @@
'board_crm_view.xml',
'res_config_view.xml',
-
],
'demo': [
'crm_demo.xml',
=== modified file 'crm/crm_lead_view.xml'
--- crm/crm_lead_view.xml 2012-11-06 15:08:13 +0000
+++ crm/crm_lead_view.xml 2012-11-12 14:47:28 +0000
@@ -169,7 +169,7 @@
<group>
<label for="contact_name" />
<div>
- <field name="contact_name" class="oe_inline"/>,
+ <field name="contact_name" class="oe_inline"/><span attrs="{'invisible': [('title', '=', '')]}">, </span>
<field name="title" placeholder="Title" domain="[('domain', '=', 'contact')]" class="oe_inline" options='{"no_open": True}'/>
</div>
<field name="email_from" widget="email"/>
=== modified file 'crm/test/process/communication_with_customer.yml'
--- crm/test/process/communication_with_customer.yml 2012-09-27 16:57:08 +0000
+++ crm/test/process/communication_with_customer.yml 2012-11-12 14:47:28 +0000
@@ -34,19 +34,3 @@
!python {model: crm.lead}: |
lead_ids = self.search(cr, uid, [('email_from','=', 'Mr. John Right <[email protected]>')])
self.convert_partner(cr, uid, lead_ids, context=context)
--
- I convert one phonecall request to a customer and put him into regular customer list.
--
- !python {model: crm.phonecall2partner}: |
- context.update({'active_model': 'crm.phonecall', 'active_ids': [ref("crm.crm_phonecall_4")], 'active_id': ref("crm.crm_phonecall_4")})
- new_id = self.create(cr, uid, {}, context=context)
- self.make_partner(cr, uid, [new_id], context=context)
--
- I check converted phonecall to partner.
--
- !python {model: res.partner}: |
- partner_id = self.search(cr, uid, [('phonecall_ids', '=', ref('crm.crm_phonecall_4'))])
- assert partner_id, "Customer is not found in regular customer list."
- data = self.browse(cr, uid, partner_id, context=context)[0]
- assert data.user_id.id == ref("base.user_root"), "User not assigned properly"
- assert data.name == "Wanted information about pricing of laptops", "Bad partner name"
=== modified file 'crm/test/process/lead2opportunity2win.yml'
--- crm/test/process/lead2opportunity2win.yml 2012-10-01 09:42:02 +0000
+++ crm/test/process/lead2opportunity2win.yml 2012-11-12 14:47:28 +0000
@@ -1,25 +1,25 @@
-
- In order to test convert customer lead into opportunity,
+ In order to test the conversion of a lead into a opportunity,
-
- I open customer lead.
+ I open a lead.
-
!python {model: crm.lead}: |
self.case_open(cr, uid, [ref("crm_case_4")])
-
- I check lead state is "Open".
+ I check if the lead state is "Open".
-
- !assert {model: crm.lead, id: crm.crm_case_4, string: Lead in open state}:
+ !assert {model: crm.lead, id: crm.crm_case_4, string: Lead state is Open}:
- state == "open"
-
I fill in a lead2partner wizard.
-
- !record {model: crm.lead2partner, id: crm_lead2partner_id1, context: '{"active_model": "crm.lead", "active_ids": [ref("crm_case_4")]}'}:
+ !record {model: crm.generate.partner, id: crm_generate_partner_id1, context: '{"active_model": "crm.lead", "active_ids": [ref("crm_case_4")]}'}:
-
I create a partner from the lead2partner wizard.
-
- !python {model: crm.lead2partner}: |
+ !python {model: crm.generate.partner}: |
context.update({'active_model': 'crm.lead', 'active_ids': [ref('crm_case_4')], 'active_id': ref('crm_case_4')})
- self.make_partner(cr, uid ,[ref("crm_lead2partner_id1")], context=context)
+ self.make_partner(cr, uid ,[ref("crm_generate_partner_id1")], context=context)
-
I convert lead into opportunity for exiting customer.
-
=== modified file 'crm/test/ui/crm_demo.yml'
--- crm/test/ui/crm_demo.yml 2012-07-30 10:29:47 +0000
+++ crm/test/ui/crm_demo.yml 2012-11-12 14:47:28 +0000
@@ -1,5 +1,5 @@
-
- I create lead record to call of partner onchange, stage onchange and Mailing opt-in onchange method.
+ I create a lead record to call a partner onchange, stage onchange and mailing opt-in onchange method.
-
!record {model: crm.lead, id: crm_case_25}:
name: 'Need more info about your pc2'
@@ -8,7 +8,7 @@
stage_id: crm.stage_lead1
state: draft
-
- I create lead record to call Mailing opt-out onchange method.
+ I create a lead record to call a mailing opt-out onchange method.
-
!record {model: crm.lead, id: crm_case_18}:
name: 'Need 20 Days of Consultancy'
@@ -16,13 +16,13 @@
state: draft
opt_out: True
-
- I create phonecall record to call partner onchange method.
+ I create a phonecall record to call a partner onchange method.
-
!record {model: crm.phonecall, id: crm_phonecall_5}:
name: 'Bad time'
partner_id: base.res_partner_5
-
- I setting next stage "New" for the lead.
+ I set the next stage to "New" for the lead.
-
!python {model: crm.lead}: |
self.stage_next(cr, uid, [ref("crm_case_4")], context={'stage_type': 'lead'})
=== modified file 'crm/wizard/__init__.py'
--- crm/wizard/__init__.py 2012-07-09 08:18:34 +0000
+++ crm/wizard/__init__.py 2012-11-12 14:47:28 +0000
@@ -19,16 +19,12 @@
#
##############################################################################
-import crm_lead_to_partner
-import crm_lead_to_opportunity
+import crm_generate_partner
import crm_phonecall_to_phonecall
import crm_opportunity_to_phonecall
-import crm_phonecall_to_partner
+import crm_lead_to_opportunity
import crm_partner_to_opportunity
import crm_phonecall_to_opportunity
-
import crm_merge_opportunities
-
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
-
=== renamed file 'crm/wizard/crm_lead_to_partner.py' => 'crm/wizard/crm_generate_partner.py'
--- crm/wizard/crm_lead_to_partner.py 2012-11-07 16:11:42 +0000
+++ crm/wizard/crm_generate_partner.py 2012-11-12 14:47:28 +0000
@@ -22,80 +22,74 @@
from osv import osv, fields
from tools.translate import _
-class crm_lead2partner(osv.osv_memory):
- """ Converts lead to partner """
- _name = 'crm.lead2partner'
- _description = 'Lead to Partner'
-
+class crm_generate_partner(osv.osv_memory):
+ """
+ Handle the partner generation from any CRM item (lead, phonecall)
+ either by explicitly converting the element to a partner, either by
+ triggering an action that will create a partner (e.g. convert a lead into
+ an opportunity).
+ """
+ _name = 'crm.generate.partner'
+ _description = 'Generate a partner from a CRM item.'
_columns = {
- 'action': fields.selection([('exist', 'Link to an existing customer'), \
- ('create', 'Create a new customer')], \
- 'Action', required=True),
+ 'action': fields.selection([
+ ('exist', 'Link to an existing customer'),
+ ('create', 'Create a new customer'),
+ ('nothing', 'Do not link to a customer')
+ ], 'Related Customer', required=True),
'partner_id': fields.many2one('res.partner', 'Customer'),
}
- def view_init(self, cr, uid, fields, context=None):
- """
- Check for precondition before wizard executes.
- """
- if context is None:
- context = {}
- model = context.get('active_model')
- model = self.pool.get(model)
- rec_ids = context and context.get('active_ids', [])
- for this in model.browse(cr, uid, rec_ids, context=context):
- if this.partner_id:
- raise osv.except_osv(_('Warning!'),
- _('A partner is already defined.'))
- def _select_partner(self, cr, uid, context=None):
+ def _find_matching_partner(self, cr, uid, context=None):
+ """
+ Try to find a matching partner regarding the active model data, like
+ the customer's name, email, phone number, etc.
+ @return partner_id if any, False otherwise
+ """
if context is None:
context = {}
- if not context.get('active_model') == 'crm.lead' or not context.get('active_id'):
- return False
- partner = self.pool.get('res.partner')
- lead = self.pool.get('crm.lead')
- this = lead.browse(cr, uid, context.get('active_id'), context=context)
- if this.partner_id:
- return this.partner_id.id
partner_id = False
- if this.email_from:
- partner_ids = partner.search(cr, uid, [('email', '=', this.email_from)], context=context)
- if partner_ids:
- partner_id = partner_ids[0]
- if not this.partner_id and this.partner_name:
- partner_ids = partner.search(cr, uid, [('name', '=', this.partner_name)], context=context)
- if partner_ids:
- partner_id = partner_ids[0]
+ partner_obj = self.pool.get('res.partner')
+
+ # The active model has to be a lead or a phonecall
+ if (context.get('active_model') == 'crm.lead') and context.get('active_id'):
+ lead_obj = self.pool.get('crm.lead')
+ lead = lead_obj.browse(cr, uid, context.get('active_id'), context=context)
+ # A partner is set already
+ if lead.partner_id:
+ partner_id = lead.partner_id.id
+ # Search through the existing partners based on the lead's email
+ elif lead.email_from:
+ partner_ids = partner_obj.search(cr, uid, [('email', '=', lead.email_from)], context=context)
+ if partner_ids:
+ partner_id = partner_ids[0]
+ # Search through the existing partners based on the lead's partner or contact name
+ elif lead.partner_name:
+ partner_ids = partner_obj.search(cr, uid, [('name', 'ilike', '%'+lead.partner_name+'%')], context=context)
+ if partner_ids:
+ partner_id = partner_ids[0]
+ elif lead.contact_name:
+ partner_ids = partner_obj.search(cr, uid, [
+ ('name', 'ilike', '%'+lead.contact_name+'%')], context=context)
+ if partner_ids:
+ partner_id = partner_ids[0]
+ elif (context.get('active_model') == 'crm.phonecall') and context.get('active_id'):
+ phonecall_obj = self.pool.get('crm.phonecall')
+ phonecall = phonecall_obj.browse(cr, uid, context.get('active_id'), context=context)
+ #do stuff
return partner_id
def default_get(self, cr, uid, fields, context=None):
- res = super(crm_lead2partner, self).default_get(cr, uid, fields, context=context)
- partner_id = self._select_partner(cr, uid, context=context)
+ res = super(crm_generate_partner, self).default_get(cr, uid, fields, context=context)
+ partner_id = self._find_matching_partner(cr, uid, context=context)
+ 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 'action' in fields:
- res.update({'action': partner_id and 'exist' or 'create'})
return res
- def open_create_partner(self, cr, uid, ids, context=None):
- """
- Open form of create partner.
- """
- view_obj = self.pool.get('ir.ui.view')
- view_id = view_obj.search(cr, uid, [('model', '=', self._name), \
- ('name', '=', self._name+'.view')])
- return {
- 'view_mode': 'form',
- 'view_type': 'form',
- 'view_id': view_id or False,
- 'res_model': self._name,
- 'context': context,
- 'type': 'ir.actions.act_window',
- 'target': 'new',
- }
-
def _create_partner(self, cr, uid, ids, context=None):
"""
Create partner based on action.
@@ -113,10 +107,10 @@
Make a partner based on action.
Only called from form view, so only meant to convert one lead at a time.
"""
- lead_id = context and context.get('active_id') or False
+ if context is None:
+ context = {}
+ lead_id = context.get('active_id', False)
partner_ids_map = self._create_partner(cr, uid, ids, context=context)
return self.pool.get('res.partner').redirect_partner_form(cr, uid, partner_ids_map.get(lead_id, False), context=context)
-crm_lead2partner()
-
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
=== modified file 'crm/wizard/crm_lead_to_opportunity.py'
--- crm/wizard/crm_lead_to_opportunity.py 2012-11-07 16:11:42 +0000
+++ crm/wizard/crm_lead_to_opportunity.py 2012-11-12 14:47:28 +0000
@@ -27,16 +27,13 @@
class crm_lead2opportunity_partner(osv.osv_memory):
_name = 'crm.lead2opportunity.partner'
_description = 'Lead To Opportunity Partner'
- _inherit = 'crm.lead2partner'
+ _inherit = 'crm.generate.partner'
_columns = {
- 'action': fields.selection([('exist', 'Link to an existing customer'), \
- ('create', 'Create a new customer'), \
- ('nothing', 'Do not link to a customer')], \
- 'Related Customer', required=True),
- 'name': fields.selection([('convert', 'Convert to opportunity'), \
- ('merge', 'Merge with existing opportunities')], \
- 'Conversion Action', required=True),
+ 'name': fields.selection([
+ ('convert', 'Convert to opportunity'),
+ ('merge', 'Merge with existing opportunities')
+ ], 'Conversion Action', required=True),
'opportunity_ids': fields.many2many('crm.lead', string='Opportunities', domain=[('type', '=', 'opportunity')]),
}
=== modified file 'crm/wizard/crm_lead_to_opportunity_view.xml'
--- crm/wizard/crm_lead_to_opportunity_view.xml 2012-09-27 13:45:13 +0000
+++ crm/wizard/crm_lead_to_opportunity_view.xml 2012-11-12 14:47:28 +0000
@@ -7,7 +7,7 @@
<field name="model">crm.lead2opportunity.partner</field>
<field name="arch" type="xml">
<form string="Convert to Opportunity" version="7.0">
- <group>
+ <group name="name">
<field name="name" class="oe_inline"/>
<field name="opportunity_ids" attrs="{'invisible': [('name', '!=', 'merge')]}">
<tree>
@@ -18,7 +18,7 @@
</tree>
</field>
</group>
- <group attrs="{'invisible': [('name', '!=', 'convert')]}">
+ <group name="action" attrs="{'invisible': [('name', '!=', 'convert')]}">
<field name="action" class="oe_inline"/>
<field name="partner_id"
attrs="{'required': [('action', '=', 'exist')], 'invisible':[('action','!=','exist')]}"
=== removed file 'crm/wizard/crm_lead_to_partner_view.xml'
--- crm/wizard/crm_lead_to_partner_view.xml 2012-08-08 12:19:50 +0000
+++ crm/wizard/crm_lead_to_partner_view.xml 1970-01-01 00:00:00 +0000
@@ -1,37 +0,0 @@
-<openerp>
- <data>
-
- <!-- Lead to Partner form view -->
-
- <record id="view_crm_lead2partner" model="ir.ui.view">
- <field name="name">crm.lead2partner.view</field>
- <field name="model">crm.lead2partner</field>
- <field name="arch" type="xml">
- <form string="Create a Partner" version="7.0">
- <group col="4">
- <separator string="Create a Partner"/>
- <field name="action"/>
- <field name="partner_id" attrs="{'required': [('action', '=', 'exist')], 'invisible':[('action','!=','exist')]}"/>
- </group>
- <footer>
- <button name="make_partner" string="Continue" type="object" class="oe_highlight"/>
- or
- <button string="Cancel" class="oe_link" special="cancel" />
- </footer>
- </form>
- </field>
- </record>
-
-
- <!-- Lead to Partner wizard -->
- <record id="action_crm_lead2partner" model="ir.actions.act_window">
- <field name="name">Create a Partner</field>
- <field name="type">ir.actions.act_window</field>
- <field name="res_model">crm.lead2partner</field>
- <field name="view_type">form</field>
- <field name="view_id" ref="view_crm_lead2partner"/>
- <field name="target">new</field>
- </record>
-
- </data>
-</openerp>
=== removed file 'crm/wizard/crm_phonecall_to_partner.py'
--- crm/wizard/crm_phonecall_to_partner.py 2012-08-23 20:06:29 +0000
+++ crm/wizard/crm_phonecall_to_partner.py 1970-01-01 00:00:00 +0000
@@ -1,67 +0,0 @@
-# -*- coding: utf-8 -*-
-##############################################################################
-#
-# OpenERP, Open Source Management Solution
-# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU Affero General Public License as
-# published by the Free Software Foundation, either version 3 of the
-# License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU Affero General Public License for more details.
-#
-# You should have received a copy of the GNU Affero General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
-#
-##############################################################################
-
-from osv import osv, fields
-from tools.translate import _
-
-class crm_phonecall2partner(osv.osv_memory):
- """ Converts phonecall to partner """
-
- _name = 'crm.phonecall2partner'
- _inherit = 'crm.lead2partner'
- _description = 'Phonecall to Partner'
-
- def _select_partner(self, cr, uid, context=None):
- """
- This function Searches for Partner from selected phonecall.
- """
- if context is None:
- context = {}
-
- phonecall_obj = self.pool.get('crm.phonecall')
- partner_obj = self.pool.get('res.partner')
- rec_ids = context and context.get('active_ids', [])
- value = {}
- partner_id = False
- for phonecall in phonecall_obj.browse(cr, uid, rec_ids, context=context):
- partner_ids = partner_obj.search(cr, uid, [('name', '=', phonecall.name or phonecall.name)])
- if not partner_ids and (phonecall.partner_phone or phonecall.partner_mobile):
- partner_ids = partner_obj.search(cr, uid, ['|', ('phone', '=', phonecall.partner_phone), ('mobile','=',phonecall.partner_mobile)])
-
- partner_id = partner_ids and partner_ids[0] or False
- return partner_id
-
-
- def _create_partner(self, cr, uid, ids, context=None):
- """
- This function Creates partner based on action.
- """
- if context is None:
- context = {}
- phonecall = self.pool.get('crm.phonecall')
- data = self.browse(cr, uid, ids, context=context)[0]
- call_ids = context and context.get('active_ids') or []
- partner_id = data.partner_id and data.partner_id.id or False
- return phonecall.convert_partner(cr, uid, call_ids, data.action, partner_id, context=context)
-
-crm_phonecall2partner()
-
-# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
=== removed file 'crm/wizard/crm_phonecall_to_partner_view.xml'
--- crm/wizard/crm_phonecall_to_partner_view.xml 2012-08-08 12:19:50 +0000
+++ crm/wizard/crm_phonecall_to_partner_view.xml 1970-01-01 00:00:00 +0000
@@ -1,54 +0,0 @@
-<openerp>
- <data>
-
- <!-- Phonecall to partner confirmation form -->
-
- <record id="view_crm_phonecall2partner_create" model="ir.ui.view">
- <field name="name">crm.phonecall2partner.view.create</field>
- <field name="model">crm.phonecall2partner</field>
- <field name="arch" type="xml">
- <form string="Create a Partner" version="7.0">
- <label string="Are you sure you want to create a partner based on this Phonecall ?"/>
- <newline/>
- <label string="You may have to verify that this partner does not exist already."/>
- <footer>
- <button name="open_create_partner" string="Create Partner" type="object" groups="base.group_partner_manager" class="oe_highlight"/>
- or
- <button string="Cancel" class="oe_link" special="cancel" />
- </footer>
- </form>
- </field>
- </record>
-
- <!-- Phonecall to partner form view -->
-
- <record id="view_crm_phonecall2partner" model="ir.ui.view">
- <field name="name">crm.phonecall2partner.view</field>
- <field name="model">crm.phonecall2partner</field>
- <field name="arch" type="xml">
- <form string="Create a Partner" version="7.0">
- <group>
- <field name="action"/>
- <field name="partner_id" attrs="{'required':[('action','=','exist')],'invisible':[('action','!=','exist')]}" />
- </group>
- <footer>
- <button name="make_partner" string="Continue" type="object" class="oe_highlight"/>
- or
- <button string="Cancel" class="oe_link" special="cancel" />
- </footer>
- </form>
- </field>
- </record>
-
- <!-- Phonecall to Partner wizard -->
-
- <record id="action_crm_phonecall2partner" model="ir.actions.act_window">
- <field name="name">Create a Partner</field>
- <field name="type">ir.actions.act_window</field>
- <field name="res_model">crm.phonecall2partner</field>
- <field name="view_type">form</field>
- <field name="view_id" ref="view_crm_phonecall2partner_create"/>
- <field name="target">new</field>
- </record>
- </data>
-</openerp>
_______________________________________________
Mailing list: https://launchpad.net/~openerp-dev-gtk
Post to : [email protected]
Unsubscribe : https://launchpad.net/~openerp-dev-gtk
More help : https://help.launchpad.net/ListHelp