[IMP] remove dead code from crm_partner_to_opportunity and crm_phonecall_to_opportunity

fp and al judged that phonecall2opp wizard was just a 'one more click' step
instead of the wizard, a phonecall will directly be converted into an opp when clicking on the 'Convert to opp' button (todo)
tests have been adapted, but some tests are still missing like 'merge lead with opp' or 'merge leads together' (todo)
documentation has been improved

bzr revid: abo@openerp.com-20121114184134-m37k9mwsq2hclgii
This commit is contained in:
Antonin Bourguignon 2012-11-14 19:41:34 +01:00
parent e726a37231
commit 6974be3d6d
11 changed files with 76 additions and 271 deletions

View File

@ -70,10 +70,8 @@ Dashboard for CRM will include:
'wizard/crm_lead_to_opportunity_view.xml',
'wizard/crm_phonecall_to_phonecall_view.xml',
'wizard/crm_phonecall_to_opportunity_view.xml',
'wizard/crm_opportunity_to_phonecall_view.xml',
'wizard/crm_partner_to_opportunity_view.xml',
'wizard/crm_merge_opportunities_view.xml',

View File

@ -247,7 +247,7 @@ Andrew</field>
<field name="contact_name">Bojing Hú</field>
<field name="partner_name">Incom Corporation</field>
<field name="email_from">bhu.a100@gmail.com</field>
<field name="partner_id" ref=""/>
<field name="partner_id" ref="base.res_partner_1"/>
<field name="country_id" ref="base.cn"/>
<field name="city">Shenzhen</field>
<field name="type_id" ref="type_lead3"/>
@ -542,6 +542,31 @@ Andrew</field>
<field eval="1" name="active"/>
</record>
<record id="crm_case_26" model="crm.lead">
<field name="type">opportunity</field>
<field name="name">Would appreciate more information about your products</field>
<field eval="11000" name="planned_revenue"/>
<field eval="45.0" name="probability"/>
<field name="partner_name">Agrolait</field>
<field name="email_from">info@agrolait.com</field>
<field name="partner_id" ref="base.res_partner_2"/>
<field name="street">69 rue de Chimay</field>
<field name="country_id" ref="base.be"/>
<field name="city">Wavre</field>
<field name="zip">1300</field>
<field name="type_id" ref="type_lead3"/>
<field name="categ_ids" eval="[(6, 0, [categ_oppor2])]"/>
<field name="channel_id" ref="crm_case_channel_website"/>
<field name="priority">3</field>
<field eval="time.strftime('%Y-%m-23')" name="date_deadline"/>
<field eval="time.strftime('%Y-%m-10')" name="date_action"/>
<field name="title_action">Send Catalogue by Email</field>
<field name="section_id" ref="crm_case_section_4"/>
<field name="user_id" ref="base.user_demo"/>
<field name="stage_id" ref="crm.stage_lead3"/>
<field eval="1" name="active"/>
</record>
<!-- Some messages linked to the previous opportunity -->
<record id="message_email0" model="mail.message">
<field name="subject">Plan to buy a Laptop</field>

View File

@ -256,14 +256,14 @@ class crm_phonecall(base_state, osv.osv):
'default_name': phonecall.name,
}
return res
# ----------------------------------------
# OpenChatter
# ----------------------------------------
def case_get_note_msg_prefix(self, cr, uid, id, context=None):
return 'Phonecall'
def case_reset_send_note(self, cr, uid, ids, context=None):
message = _('Phonecall has been <b>reset and set as open</b>.')
return self.message_post(cr, uid, ids, body=message, context=context)
@ -286,5 +286,9 @@ class crm_phonecall(base_state, osv.osv):
def _call_set_partner_send_note(self, cr, uid, ids, context=None):
return self.message_post(cr, uid, ids, body=_("Partner has been <b>created</b>."), context=context)
def action_button_convert2opportunity(self, cr, uid, ids, context=None):
#TODO
assert len(ids) == 1, 'This option should only be used for a single id at a time.'
return {}
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -39,7 +39,7 @@
<field name="key2">client_action_multi</field>
</record>
<!-- Phonecall Categories Form View -->
<!-- Phonecall Categories Form View -->
<record id="crm_phonecall_categ_action" model="ir.actions.act_window">
<field name="name">Phonecall Categories</field>
<field name="res_model">crm.case.categ</field>
@ -60,8 +60,7 @@
<menuitem action="crm_phonecall_categ_action" name="Categories"
id="menu_crm_case_phonecall-act" parent="menu_crm_config_phonecall" groups="base.group_no_one"/>
<!-- PhoneCalls Tree View -->
<!-- Phonecalls Tree View -->
<record model="ir.ui.view" id="crm_case_phone_tree_view">
<field name="name">CRM - Phone Calls Tree</field>
<field name="model">crm.phonecall</field>
@ -74,10 +73,10 @@
states="open,pending" icon="gtk-redo"
name="action_make_meeting" type="object"/>
<button string="Convert to Opportunity"
name="%(phonecall2opportunity_act)d"
name="action_button_convert2opportunity"
states="open,pending"
icon="gtk-index"
type="action" attrs="{'invisible':[('opportunity_id','!=',False)]}"/>
type="object" attrs="{'invisible':[('opportunity_id','!=',False)]}"/>
<field name="partner_phone"/>
<field name="user_id"/>
<field name="categ_id" invisible="1"/>
@ -96,26 +95,25 @@
</field>
</record>
<!-- Phonecalls Form View -->
<!-- Phonecalls Form View -->
<record model="ir.ui.view" id="crm_case_phone_form_view">
<field name="name">CRM - Phone Call Form</field>
<field name="model">crm.phonecall</field>
<field name="arch" type="xml">
<form string="Phone Call" version="7.0">
<header>
<button name="case_close" string="Call Done" type="object" class="oe_highlight"
states="open,pending"/>
<button name="case_reset" string="Reset to Todo" type="object"
states="cancel"/>
<button name="case_cancel" string="Cancel" type="object"
states="draft,open,pending"/>
<field name="state" widget="statusbar" nolabel="1" statusbar_visible="open,done"/>
</header>
<header>
<button name="case_close" string="Call Done" type="object" class="oe_highlight"
states="open,pending"/>
<button name="case_reset" string="Reset to Todo" type="object"
states="cancel"/>
<button name="case_cancel" string="Cancel" type="object"
states="draft,open,pending"/>
<field name="state" widget="statusbar" nolabel="1" statusbar_visible="open,done"/>
</header>
<sheet string="Phone Call">
<div class="oe_right">
<div class="oe_right">
<button string="Convert to Opportunity"
name="%(phonecall2opportunity_act)d"
name="action_button_convert2opportunity"
type="action"
attrs="{'invisible':[ '|', ('opportunity_id','!=',False), ('state', 'not in', ('open', 'done'))]}"/>
<button string="Schedule Other Call"
@ -133,7 +131,7 @@
</div>
<h2><field name="partner_phone"/></h2>
</div>
<group col="4">
<field name="date"/>
<field name="user_id"/>
@ -158,7 +156,6 @@
</record>
<!--Logged Phonecalls Tree View -->
<record model="ir.ui.view" id="crm_case_inbound_phone_tree_view">
<field name="name">CRM - Logged Phone Calls Tree</field>
<field name="model">crm.phonecall</field>
@ -185,7 +182,7 @@
icon="gtk-redo"
name="action_make_meeting" type="object"/>
<button string="Convert to Opportunity"
name="%(phonecall2opportunity_act)d"
name="action_button_convert2opportunity"
states="open,pending"
icon="gtk-index"
type="action" attrs="{'invisible':[('opportunity_id','!=',False)]}"/>
@ -194,7 +191,6 @@
</record>
<!-- Phonecalls Calendar View -->
<record model="ir.ui.view" id="crm_case_phone_calendar_view">
<field name="name">CRM - Phone Calls Calendar</field>
<field name="model">crm.phonecall</field>

View File

@ -1,22 +1,9 @@
-
I make an opportunity from customer.
-
!python {model: crm.partner2opportunity}: |
context.update({'active_model': 'res.partner', 'active_ids': [ref("base.res_partner_9")]})
res_id = self.create(cr, uid, {'name': "Enquête pour l'achat de services"}, context=context)
self.make_opportunity(cr, uid, [res_id], context=context)
-
I make another opportunity from a phone call with the same customer.
-
!python {model: crm.phonecall2opportunity}: |
context.update({'active_model': 'crm.phonecall', 'active_ids': [ref("crm.crm_phonecall_6")]})
res_id = self.create(cr, uid, {'name': "À propos du prix de votre autre service", 'partner_id': ref("base.res_partner_9")}, context=context)
self.make_opportunity(cr, uid, [res_id], context=context)
-
Now I merge these opportunities.
I merge two opportunities.
-
!python {model: crm.lead}: |
opportunity_ids = self.search(cr, uid, [('partner_id','=', ref("base.res_partner_9"))])
opportunity_ids = self.search(cr, uid, [('type', '=', 'opportunity'), ('state', 'not in', ['done', 'cancel']), ('partner_id', '=', ref('base.res_partner_2'))], limit=2)
assert len(opportunity_ids) == 2, 'There should be two opportunities (got %s instead)' % len(opportunity_ids)
context.update({'active_model': 'crm.lead', 'active_ids': opportunity_ids, 'active_id': opportunity_ids[0]})
-
!record {model: crm.merge.opportunity, id: opportunity_merge_id }:
@ -27,8 +14,8 @@
I check for merged opportunities for customer.
-
!python {model: crm.lead}: |
merge_id = self.search(cr, uid, [('partner_id','=', ref("base.res_partner_9"))])
merge_id = self.search(cr, uid, [('partner_id','=', ref("base.res_partner_2"))])
assert merge_id, 'Fail to create Merge opportunity'
merge_data = self.browse(cr, uid, merge_id)[0]
assert merge_data.type == 'opportunity', 'Merged opportunity type not change!'
assert merge_data.partner_id.id == ref("base.res_partner_9"), 'Partner missmatch!'
assert merge_data.type == 'opportunity', 'Merged opportunity type didn\'t change'
assert merge_data.partner_id.id == ref("base.res_partner_2"), 'Partner missmatch'

View File

@ -23,8 +23,6 @@ import crm_partner_binding
import crm_phonecall_to_phonecall
import crm_opportunity_to_phonecall
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:

View File

@ -21,17 +21,27 @@ from osv import osv, fields
from tools.translate import _
class crm_merge_opportunity(osv.osv_memory):
"""Merge two Opportunities"""
"""
Merge two opportunities together.
If we're talking about opportunities, it's just because it makes more sense
to merge opps than leads, because the leads are more ephemeral objects.
But since opportunities are leads, it's also possible to merge leads
together (resulting in a new lead), or leads and opps together (resulting
in a new opp).
"""
_name = 'crm.merge.opportunity'
_description = 'Merge two Opportunities'
_description = 'Merge two opportunities'
_columns = {
'opportunity_ids': fields.many2many('crm.lead', rel='merge_opportunity_rel', id1='merge_id', id2='opportunity_id', string='Leads/Opportunities'),
}
def action_merge(self, cr, uid, ids, context=None):
if context is None:
context = {}
lead = self.pool.get('crm.lead')
record = self.browse(cr, uid, ids[0], context=context)
opportunities = record.opportunity_ids
wizard = self.browse(cr, uid, ids[0], context=context)
opportunities = wizard.opportunity_ids
#TOFIX: why need to check lead_ids here
lead_ids = [opportunities[0].id]
self.write(cr, uid, ids, {'opportunity_ids' : [(6,0, lead_ids)]}, context=context)
@ -39,15 +49,15 @@ class crm_merge_opportunity(osv.osv_memory):
merge_id = lead.merge_opportunity(cr, uid, [x.id for x in opportunities], context=context)
return lead.redirect_opportunity_view(cr, uid, merge_id, context=context)
_columns = {
'opportunity_ids': fields.many2many('crm.lead', rel='merge_opportunity_rel', id1='merge_id', id2='opportunity_id', string='Leads/Opportunities'),
}
def default_get(self, cr, uid, fields, context=None):
"""
This function gets default values
Use active_ids from the context to fetch the leads/opps to merge.
In order to get merged, these leads/opps have can't be in 'Done' or
'Candel' state.
"""
record_ids = context and context.get('active_ids', False) or False
if context is None:
context = {}
record_ids = context.get('active_ids', False)
res = super(crm_merge_opportunity, self).default_get(cr, uid, fields, context=context)
if record_ids:
@ -61,6 +71,4 @@ class crm_merge_opportunity(osv.osv_memory):
return res
crm_merge_opportunity()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -1,77 +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_partner2opportunity(osv.osv_memory):
"""Converts Partner To Opportunity"""
_name = 'crm.partner2opportunity'
_description = 'Partner To Opportunity'
_columns = {
'name' : fields.char('Opportunity Name', size=64, required=True),
'planned_revenue': fields.float('Expected Revenue', digits=(16,2)),
'probability': fields.float('Success Probability', digits=(16,2)),
'partner_id': fields.many2one('res.partner', 'Customer'),
}
def action_cancel(self, cr, uid, ids, context=None):
"""
Closes Partner 2 Opportunity
"""
return {'type':'ir.actions.act_window_close'}
def default_get(self, cr, uid, fields, context=None):
"""
This function gets default values
"""
partner_obj = self.pool.get('res.partner')
data = context and context.get('active_ids', []) or []
res = super(crm_partner2opportunity, self).default_get(cr, uid, fields, context=context)
for partner in partner_obj.browse(cr, uid, data, []):
if 'name' in fields:
res.update({'name': partner.name})
if 'partner_id' in fields:
res.update({'partner_id': data and data[0] or False})
return res
def make_opportunity(self, cr, uid, ids, context=None):
partner_ids = context and context.get('active_ids', []) or []
partner_id = partner_ids[0] if partner_ids else None
partner = self.pool.get('res.partner')
lead = self.pool.get('crm.lead')
data = self.browse(cr, uid, ids, context=context)[0]
opportunity_ids = partner.make_opportunity(cr, uid, partner_ids,
data.name,
data.planned_revenue,
data.probability,
partner_id,
context=context,
)
opportunity_id = opportunity_ids[partner_ids[0]]
return lead.redirect_opportunity_view(cr, uid, opportunity_id, context=context)
crm_partner2opportunity()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -1,27 +0,0 @@
<openerp>
<data>
<!-- partner To Opportunity form -->
<record id="view_crm_partner2opportunity" model="ir.ui.view">
<field name="name">crm.crm.partner2opportunity</field>
<field name="model">crm.partner2opportunity</field>
<field name="arch" type="xml">
<form string="Create Opportunity" version="7.0">
<group col="4">
<field name="name"/>
<field name="partner_id"/>
<field name="planned_revenue"/>
<field name="probability"/>
</group>
<footer>
<button name="make_opportunity" string="Create Opportunity" type="object" class="oe_highlight"/>
or
<button string="Cancel" class="oe_link" special="cancel" />
</footer>
</form>
</field>
</record>
</data>
</openerp>

View File

@ -1,65 +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_phonecall2opportunity(osv.osv_memory):
""" Converts Phonecall to Opportunity"""
_name = 'crm.phonecall2opportunity'
_inherit = 'crm.partner2opportunity'
_description = 'Phonecall To Opportunity'
def make_opportunity(self, cr, uid, ids, context=None):
"""
This converts Phonecall to Opportunity and opens Phonecall view
"""
if not len(ids):
return False
call_ids = context and context.get('active_ids', False) or False
this = self.browse(cr, uid, ids[0], context=context)
if not call_ids:
return {}
opportunity = self.pool.get('crm.lead')
phonecall = self.pool.get('crm.phonecall')
opportunity_ids = phonecall.convert_opportunity(cr, uid, call_ids, this.name, this.partner_id and this.partner_id.id or False, \
this.planned_revenue, this.probability, context=context)
return opportunity.redirect_opportunity_view(cr, uid, opportunity_ids[call_ids[0]], context=context)
def default_get(self, cr, uid, fields, context=None):
"""
This function gets default values
"""
record_id = context and context.get('active_id', False) or False
res = {}
if record_id:
phonecall = self.pool.get('crm.phonecall').browse(cr, uid, record_id, context=context)
if 'name' in fields:
res.update({'name': phonecall.name})
if 'partner_id' in fields:
res.update({'partner_id': phonecall.partner_id and phonecall.partner_id.id or False})
return res
crm_phonecall2opportunity()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -1,42 +0,0 @@
<?xml version="1.0"?>
<openerp>
<data>
<!-- Phonecall to Opportunity view -->
<record model="ir.ui.view" id="phonecall2opportunity_view">
<field name="name">crm.phonecall2opportunity.form</field>
<field name="model">crm.phonecall2opportunity</field>
<field name="arch" type="xml">
<form string="Convert To Opportunity " version="7.0">
<group>
<field name="name"/>
<field name="partner_id" />
<label for="planned_revenue"/>
<div>
<field name="planned_revenue" class="oe_inline"/> at
<field name="probability" class="oe_inline"/> %%
</div>
</group>
<footer>
<button name="make_opportunity" type="object" string="_Convert" class="oe_highlight"/>
or
<button string="Cancel" class="oe_link" special="cancel" />
</footer>
</form>
</field>
</record>
<!-- Phonecall to Opportunity action -->
<record model="ir.actions.act_window" id="phonecall2opportunity_act">
<field name="name">Convert to opportunity</field>
<field name="res_model">crm.phonecall2opportunity</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="view_id" ref="phonecall2opportunity_view"/>
<field name="target">new</field>
</record>
</data>
</openerp>