[REF]: crm: * Improvement in lead, opportunity wizard

* Improved code quality
* Put proper docstring

bzr revid: rpa@tinyerp.com-20100317125711-z59f06w4x8fdefl1
This commit is contained in:
rpa (Open ERP) 2010-03-17 18:27:11 +05:30
parent de233b8fe1
commit bd9e9ef507
11 changed files with 290 additions and 198 deletions

View File

@ -66,7 +66,7 @@ between mails and Open ERP.""",
'wizard/crm_phonecall2phonecall.xml',
'wizard/phonecall2meeting.xml',
'wizard/phonecall2partner_view.xml',
'wizard/phonecall2opportunity.xml',
'wizard/crm_phonecall_to_opportunity_view.xml',
'wizard/crm_opportunity_to_meeting_view.xml',
'wizard/crm_opportunity_to_phonecall_view.xml',
'crm_wizard.xml',

View File

@ -86,7 +86,7 @@
icon="gtk-index" type="action"
attrs="{'invisible':[('opportunity_id','!=',False)]}" />
<label colspan="6" string=""/>
<button string="Schedule Call Other"
<button string="Schedule Other Call"
icon="gtk-redo"
name="%(phonecall_to_phonecall_act)d"
type="action" />

View File

@ -34,7 +34,7 @@ import crm_opportunity_to_phonecall
import crm_phonecall2phonecall
import phonecall2partner
import phonecall2meeting
import phonecall_to_opportunity
import crm_phonecall_to_opportunity
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -65,34 +65,35 @@ class crm_lead2opportunity(osv.osv_memory):
id2 = data_obj.browse(cr, uid, id2, context=context).res_id
if id3:
id3 = data_obj.browse(cr, uid, id3, context=context).res_id
for this in self.browse(cr, uid, ids, context=context):
lead = lead_obj.browse(cr, uid, record_id, context=context)
new_opportunity_id = opp_obj.create(cr, uid, {
'name': this.name,
'planned_revenue': this.planned_revenue,
'probability': this.probability,
'partner_id': lead.partner_id and lead.partner_id.id or False ,
'section_id': lead.section_id and lead.section_id.id or False,
'description': lead.description or False,
'date_deadline': lead.date_deadline or False,
'partner_address_id': lead.partner_address_id and \
lead.partner_address_id.id or False ,
'priority': lead.priority,
'phone': lead.phone,
'email_from': lead.email_from
})
new_opportunity = opp_obj.browse(cr, uid, new_opportunity_id)
vals = {
'partner_id': this.partner_id and this.partner_id.id or False,
}
if not lead.opportunity_id:
vals.update({'opportunity_id' : new_opportunity.id})
lead_obj.write(cr, uid, [lead.id], vals)
lead_obj.case_close(cr, uid, [lead.id])
opp_obj.case_open(cr, uid, [new_opportunity_id])
for this in self.browse(cr, uid, ids, context=context):
new_opportunity_id = opp_obj.create(cr, uid, {
'name': this.name,
'planned_revenue': this.planned_revenue,
'probability': this.probability,
'partner_id': lead.partner_id and lead.partner_id.id or False ,
'section_id': lead.section_id and lead.section_id.id or False,
'description': lead.description or False,
'date_deadline': lead.date_deadline or False,
'partner_address_id': lead.partner_address_id and \
lead.partner_address_id.id or False ,
'priority': lead.priority,
'phone': lead.phone,
'email_from': lead.email_from
})
new_opportunity = opp_obj.browse(cr, uid, new_opportunity_id)
vals = {
'partner_id': this.partner_id and this.partner_id.id or False,
}
if not lead.opportunity_id:
vals.update({'opportunity_id' : new_opportunity.id})
lead_obj.write(cr, uid, [lead.id], vals)
lead_obj.case_close(cr, uid, [lead.id])
opp_obj.case_open(cr, uid, [new_opportunity_id])
value = {
'name': _('Opportunity'),

View File

@ -68,7 +68,6 @@ class crm_opportunity2meeting(osv.osv_memory):
if id3:
id3 = data_obj.browse(cr, uid, id3, context=context).res_id
for this in self.browse(cr, uid, ids, context=context):
opp = opp_obj.browse(cr, uid, record_id, context=context)
context = {
'default_opportunity_id': opp.id,

View File

@ -23,6 +23,8 @@ from osv import osv, fields
from tools.translate import _
class crm_opportunity2phonecall(osv.osv_memory):
"""Converts Opportunity to Phonecall"""
_name = 'crm.opportunity2phonecall'
_description = 'Opportunity to Phonecall'
@ -85,8 +87,11 @@ class crm_opportunity2phonecall(osv.osv_memory):
result = mod_obj._get_id(cr, uid, 'crm', 'view_crm_case_phonecalls_filter')
res = mod_obj.read(cr, uid, result, ['res_id'])
# Select the view
data_obj = self.pool.get('ir.model.data')
categ_id = mod_obj._get_id(cr, uid, 'crm', 'categ_phone1')
categ_id = data_obj.browse(cr, uid, categ_id, context=context).res_id
# Select the view
id2 = data_obj._get_id(cr, uid, 'crm', 'crm_case_phone_tree_view')
id3 = data_obj._get_id(cr, uid, 'crm', 'crm_case_phone_form_view')
if id2:
@ -100,7 +105,7 @@ class crm_opportunity2phonecall(osv.osv_memory):
'name' : opp.name,
'case_id' : opp.id ,
'user_id' : this.user_id and this.user_id.id or False,
'categ_id' : opp.categ_id and opp.categ_id.id or False,
'categ_id' : categ_id,
'description' : opp.description or False,
'date' : this.date,
'section_id' : opp.section_id and opp.section_id.id or False,

View File

@ -1,88 +1,131 @@
# -*- encoding: utf-8 -*-
############################################################################################
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
# Copyright (C) 2008-2009 AJM Technologies S.A. (<http://www.ajm.lu). All Rights Reserved
# $Id$
# 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 General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# 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 General Public License for more details.
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# 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
import netsvc
import time
import tools
import mx.DateTime
from tools import config
from tools.translate import _
import tools
class crm_phonecall2phonecall(osv.osv_memory):
""" Converts Phonecall to Phonecall"""
_name = 'crm.phonecall2phonecall'
_description = 'Phonecall To Phonecall'
def action_cancel(self, cr, uid, ids, context=None):
"""
Closes Phonecall to Phonecall form
@param self: The object pointer
@param cr: the current row, from the database cursor,
@param uid: the current users ID for security checks,
@param ids: List of Phonecall to Phonecall's IDs
@param context: A standard dictionary for contextual values
"""
return {'type':'ir.actions.act_window_close'}
def action_apply(self, cr, uid, ids, context=None):
this = self.browse(cr, uid, ids)[0]
values={}
record_id = context and context.get('record_id', False) or False
"""
This converts Phonecall to Phonecall and opens Phonecall view
@param self: The object pointer
@param cr: the current row, from the database cursor,
@param uid: the current users ID for security checks,
@param ids: List of Phonecall to Phonecall IDs
@param context: A standard dictionary for contextual values
@return : Dictionary value for created Opportunity form
"""
res = {}
record_id = context and context.get('active_id', False) or False
phonecall_obj = self.pool.get('crm.phonecall')
if record_id:
for case in self.pool.get('crm.phonecall').browse(cr, uid, [record_id], context=context):
values['name']=this.name
values['user_id']=this.user_id and this.user_id.id
values['categ_id']=case.categ_id and case.categ_id.id or False
values['section_id']=case.section_id and case.section_id.id
values['description']=case.description or ''
values['partner_id']=case.partner_id.id
values['partner_address_id']=case.partner_address_id.id
values['partner_mobile']=case.partner_mobile or False
values['priority']=case.priority
values['partner_phone']=case.partner_phone or False
values['date']=this.date
phonecall_proxy = self.pool.get('crm.phonecall')
phonecall_id = phonecall_proxy.create(cr, uid, values, context=context)
value = {
data_obj = self.pool.get('ir.model.data')
# Get Phonecall views
result = data_obj._get_id(cr, uid, 'crm', 'view_crm_case_phonecalls_filter')
res = data_obj.read(cr, uid, result, ['res_id'])
id2 = data_obj._get_id(cr, uid, 'crm', 'crm_case_phone_form_view')
id3 = data_obj._get_id(cr, uid, 'crm', 'crm_case_phone_tree_view')
if id2:
id2 = data_obj.browse(cr, uid, id2, context=context).res_id
if id3:
id3 = data_obj.browse(cr, uid, id3, context=context).res_id
phonecall = phonecall_obj.browse(cr, uid, record_id, context=context)
for this in self.browse(cr, uid, ids, context=context):
values = {
'name': this.name,
'user_id': this.user_id and this.user_id.id,
'categ_id': phonecall.categ_id and phonecall.categ_id.id or False,
'section_id': phonecall.section_id and phonecall.section_id.id,
'description': phonecall.description or '',
'partner_id': phonecall.partner_id.id,
'partner_address_id': phonecall.partner_address_id.id,
'partner_mobile': phonecall.partner_mobile or False,
'priority': phonecall.priority,
'partner_phone': phonecall.partner_phone or False,
'date': this.date
}
phonecall_id = phonecall_obj.create(cr, uid, values, context=context)
print phonecall_id
res = {
'name': _('Phone Call'),
'view_type': 'form',
'view_mode': 'form',
'res_model': 'crm.phonecall',
'view_id': False,
'views': [(id2, 'form'), (id3, 'tree'), (False, 'calendar'), (False, 'graph')],
'type': 'ir.actions.act_window',
'res_id': phonecall_id
}
return value
return res
_columns = {
'name' : fields.char('Call summary', size=64, required=True, select=1),
'user_id' : fields.many2one('res.users',"Assign To"),
'date': fields.datetime('Date'),
'section_id':fields.many2one('crm.case.section','Sales Team'),
}
'name' : fields.char('Call summary', size=64, required=True, select=1),
'user_id' : fields.many2one('res.users',"Assign To"),
'date': fields.datetime('Date'),
'section_id':fields.many2one('crm.case.section','Sales Team'),
}
def default_get(self, cr, uid, fields, context=None):
record_id = context and context.get('record_id', False) or False
res = super(crm_phonecall2phonecall, self).default_get(cr, uid, fields, context=context)
"""
This function gets default values
@param self: The object pointer
@param cr: the current row, from the database cursor,
@param uid: the current users ID for security checks,
@param fields: List of fields for default value
@param context: A standard dictionary for contextual values
@return : default values of fields.
"""
record_id = context and context.get('active_id', False) or False
if record_id:
phonecall_id = self.pool.get('crm.phonecall').browse(cr, uid, record_id, context=context)
res['name']=phonecall_id.name
res['user_id']=phonecall_id.user_id and phonecall_id.user_id.id or False
res['date']=phonecall_id.date
res['section_id']=phonecall_id.section_id and phonecall_id.section_id.id or False
phonecall = self.pool.get('crm.phonecall').browse(cr, uid, record_id, context=context)
res = {
'name': phonecall.name,
'user_id': phonecall.user_id and phonecall.user_id.id or False,
'date': phonecall.date,
'section_id': phonecall.section_id and phonecall.section_id.id or False
}
return res
crm_phonecall2phonecall()
crm_phonecall2phonecall()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -1,23 +1,31 @@
<?xml version="1.0"?>
<openerp>
<data>
<!-- Phonecall to Phonecall view -->
<record model="ir.ui.view" id="phonecall_to_phonecall_view">
<field name="name">crm.phonecall2phonecall.form</field>
<field name="model">crm.phonecall2phonecall</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Schedule Other Call" col="2">
<form string="Schedule Other Call">
<field name="name"/>
<field name="user_id" />
<field name="date" string="Planned Date"/>
<field name="section_id"/>
<group colspan="2" col="2" >
<separator string=" " colspan="4"/>
<group colspan="4" col="3" >
<label string=" " />
<button name="action_cancel" string="_Cancel" icon="gtk-cancel" special="cancel" />
<button name="action_apply" type="object" string="_Apply" icon="gtk-apply" />
<button name="action_apply" type="object" string="_Schedule" icon="gtk-go-forward" />
</group>
</form>
</field>
</record>
<!-- Phonecall to Phonecall action -->
<record model="ir.actions.act_window" id="phonecall_to_phonecall_act">
<field name="name">Schedule Other Call</field>
<field name="res_model">crm.phonecall2phonecall</field>
@ -25,7 +33,7 @@
<field name="view_mode">form</field>
<field name="view_id" ref="phonecall_to_phonecall_view"/>
<field name="target">new</field>
<field name="context">{'record_id' : active_id}</field>
</record>
</data>
</openerp>

View File

@ -0,0 +1,135 @@
# -*- 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'
_description = 'Phonecall To Opportunity'
def action_cancel(self, cr, uid, ids, context=None):
"""
Closes Phonecall to Opportunity form
@param self: The object pointer
@param cr: the current row, from the database cursor,
@param uid: the current users ID for security checks,
@param ids: List of Phonecall to Opportunity's IDs
@param context: A standard dictionary for contextual values
"""
return {'type':'ir.actions.act_window_close'}
def action_apply(self, cr, uid, ids, context=None):
"""
This converts Phonecall to Opportunity and opens Phonecall view
@param self: The object pointer
@param cr: the current row, from the database cursor,
@param uid: the current users ID for security checks,
@param ids: List of Phonecall to Opportunity IDs
@param context: A standard dictionary for contextual values
@return : Dictionary value for created Opportunity form
"""
record_id = context and context.get('active_id', False) or False
if record_id:
opp_obj = self.pool.get('crm.opportunity')
phonecall_obj = self.pool.get('crm.phonecall')
case = phonecall_obj.browse(cr, uid, record_id, context=context)
if case.state in ['done', 'cancel']:
raise osv.except_osv(_("Warning"), _("Closed/Cancelled Phone \
Call Could not convert into Opportunity"))
else:
data_obj = self.pool.get('ir.model.data')
result = data_obj._get_id(cr, uid, 'crm', 'view_crm_case_opportunities_filter')
res = data_obj.read(cr, uid, result, ['res_id'])
id2 = data_obj._get_id(cr, uid, 'crm', 'crm_case_form_view_oppor')
id3 = data_obj._get_id(cr, uid, 'crm', 'crm_case_tree_view_oppor')
if id2:
id2 = data_obj.browse(cr, uid, id2, context=context).res_id
if id3:
id3 = data_obj.browse(cr, uid, id3, context=context).res_id
for this in self.browse(cr, uid, ids, context=context):
new_opportunity_id = opp_obj.create(cr, uid, {
'name': this.name,
'planned_revenue': this.planned_revenue,
'probability': this.probability,
'partner_id': this.partner_id and this.partner_id.id or False,
'section_id': case.section_id and case.section_id.id or False,
'description': case.description or False,
'phonecall_id': case.id,
'priority': case.priority,
'phone': case.partner_phone or False,
})
new_opportunity = opp_obj.browse(cr, uid, new_opportunity_id)
vals = {
'partner_id': this.partner_id.id,
'opportunity_id' : new_opportunity_id,
}
phonecall_obj.write(cr, uid, [case.id], vals)
phonecall_obj.case_close(cr, uid, [case.id])
opp_obj.case_open(cr, uid, [new_opportunity_id])
value = {
'name': _('Opportunity'),
'view_type': 'form',
'view_mode': 'form,tree',
'res_model': 'crm.opportunity',
'res_id': int(new_opportunity_id),
'view_id': False,
'views': [(id2, 'form'), (id3, 'tree'), (False, 'calendar'), (False, 'graph')],
'type': 'ir.actions.act_window',
'search_view_id': res['res_id']
}
return value
_columns = {
'name' : fields.char('Opportunity Summary', size=64, required=True, select=1),
'probability': fields.float('Success Probability'),
'planned_revenue': fields.float('Expected Revenue'),
'partner_id': fields.many2one('res.partner', 'Partner'),
}
def default_get(self, cr, uid, fields, context=None):
"""
This function gets default values
@param self: The object pointer
@param cr: the current row, from the database cursor,
@param uid: the current users ID for security checks,
@param fields: List of fields for default value
@param context: A standard dictionary for contextual values
@return : default values of fields.
"""
record_id = context and context.get('active_id', False) or False
if record_id:
phonecall = self.pool.get('crm.phonecall').browse(cr, uid, record_id, context=context)
res = {
'name': phonecall.name,
'partner_id': phonecall.partner_id and phonecall.partner_id.id or False
}
return res
crm_phonecall2opportunity()

View File

@ -1,24 +1,32 @@
<?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="type">form</field>
<field name="arch" type="xml">
<form string="Convert To Opportunity " col="2">
<form string="Convert To Opportunity ">
<field name="name"/>
<field name="partner_id" />
<newline/>
<field name="planned_revenue"/>
<field name="probability"/>
<group colspan="2" col="2" >
<separator string=" " colspan="4"/>
<group colspan="4" col="3" >
<label string=" " />
<button name="action_cancel" string="_Cancel" icon="gtk-cancel" special="cancel" />
<button name="action_apply" type="object" string="_Apply" icon="gtk-apply" />
<button name="action_apply" type="object" string="_Convert" icon="gtk-convert" />
</group>
</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>
@ -26,7 +34,7 @@
<field name="view_mode">form</field>
<field name="view_id" ref="phonecall2opportunity_view"/>
<field name="target">new</field>
<field name="context">{'record_id' : active_id}</field>
</record>
</data>
</openerp>

View File

@ -1,107 +0,0 @@
# -*- encoding: utf-8 -*-
############################################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
# Copyright (C) 2008-2009 AJM Technologies S.A. (<http://www.ajm.lu). All Rights Reserved
# $Id$
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
############################################################################################
############################################################################################
from osv import osv, fields
import netsvc
import time
import tools
import mx.DateTime
from tools import config
from tools.translate import _
import tools
class crm_phonecall2opportunity(osv.osv_memory):
_name = 'crm.phonecall2opportunity'
_description = 'Phonecall To Opportunity'
def action_cancel(self, cr, uid, ids, context=None):
return {'type':'ir.actions.act_window_close'}
def action_apply(self, cr, uid, ids, context=None):
this = self.browse(cr, uid, ids[0], context=context)
record_id = context and context.get('record_id', False) or False
if record_id:
for case in self.pool.get('crm.phonecall').browse(cr, uid, [record_id], context=context):
if case.state in ['done', 'cancel']:
raise osv.except_osv(_("Warning"),
_("Closed/Cancelled Phone Call Could not convert into Opportunity"))
else:
data_obj = self.pool.get('ir.model.data')
result = data_obj._get_id(cr, uid, 'crm', 'view_crm_case_opportunities_filter')
res = data_obj.read(cr, uid, result, ['res_id'])
id2 = data_obj._get_id(cr, uid, 'crm', 'crm_case_form_view_oppor')
id3 = data_obj._get_id(cr, uid, 'crm', 'crm_case_tree_view_oppor')
if id2:
id2 = data_obj.browse(cr, uid, id2, context=context).res_id
if id3:
id3 = data_obj.browse(cr, uid, id3, context=context).res_id
opportunity_case_obj = self.pool.get('crm.opportunity')
phonecall_case_obj = self.pool.get('crm.phonecall')
new_opportunity_id = opportunity_case_obj.create(cr, uid, {
'name': this.name,
'planned_revenue': this.planned_revenue,
'probability': this.probability,
'partner_id': this.partner_id and this.partner_id.id or False,
'section_id': case.section_id and case.section_id.id or False,
'description': case.description or False,
'phonecall_id': case.id,
'priority': case.priority,
'phone': case.partner_phone or False,
})
new_opportunity = opportunity_case_obj.browse(cr, uid, new_opportunity_id)
vals = {
'partner_id': this.partner_id.id,
'opportunity_id' : new_opportunity_id,
}
phonecall_case_obj.write(cr, uid, [case.id], vals)
phonecall_case_obj.case_close(cr, uid, [case.id])
phonecall_case_obj.case_open(cr, uid, [new_opportunity_id])
value = {
'name': _('Opportunity'),
'view_type': 'form',
'view_mode': 'form,tree',
'res_model': 'crm.opportunity',
'res_id': int(new_opportunity_id),
'view_id': False,
'views': [(id2,'form'),(id3,'tree'),(False,'calendar'),(False,'graph')],
'type': 'ir.actions.act_window',
'search_view_id': res['res_id']
}
return value
_columns = {
'name' : fields.char('Opportunity Summary', size=64, required=True, select=1),
'probability': fields.float('Success Probability'),
'planned_revenue': fields.float('Expected Revenue'),
'partner_id': fields.many2one('res.partner', 'Partner'),
}
def default_get(self, cr, uid, fields, context=None):
record_id = context and context.get('record_id', False) or False
res = super(crm_phonecall2opportunity, self).default_get(cr, uid, fields, context=context)
if record_id:
phonecall_id = self.pool.get('crm.phonecall').browse(cr, uid, record_id, context=context)
res['name']=phonecall_id.name
res['partner_id']=phonecall_id.partner_id and phonecall_id.partner_id.id
return res
crm_phonecall2opportunity()