[IMP]: crm: Improvement in phonecall to partner wizard + Added proper docstring

bzr revid: rpa@tinyerp.com-20100317132704-4fzstp888prq7b3k
This commit is contained in:
rpa (Open ERP)
2010-03-17 18:57:04 +05:30
parent bd9e9ef507
commit 4470f8aad1
7 changed files with 248 additions and 203 deletions
+1 -1
View File
@@ -65,7 +65,7 @@ between mails and Open ERP.""",
'wizard/crm_lead_to_opportunity_view.xml',
'wizard/crm_phonecall2phonecall.xml',
'wizard/phonecall2meeting.xml',
'wizard/phonecall2partner_view.xml',
'wizard/crm_phonecall_to_partner_view.xml',
'wizard/crm_phonecall_to_opportunity_view.xml',
'wizard/crm_opportunity_to_meeting_view.xml',
'wizard/crm_opportunity_to_phonecall_view.xml',
+1 -1
View File
@@ -32,7 +32,7 @@ import crm_opportunity_to_meeting
import crm_opportunity_to_phonecall
import crm_phonecall2phonecall
import phonecall2partner
import crm_phonecall_to_partner
import phonecall2meeting
import crm_phonecall_to_opportunity
@@ -11,6 +11,7 @@
<form string="Create a Partner?">
<label string="Are you sure you want to create a partner based on this lead ?" colspan="4"/>
<label string="You may have to verify that this partner does not exist already." colspan="4"/>
<separator string="" colspan="4" />
<group col="4" colspan="4">
<button special="cancel" string="_Cancel" icon="gtk-cancel"/>
<button name="open_create_partner" string="Create _Partner" type="object" icon="gtk-ok"/>
@@ -31,6 +32,7 @@
<group attrs="{'invisible':[('action','!=','exist')]}">
<field name="partner_id" attrs="{'required': [('action', '=', 'exist')]}"/>
</group>
<separator string="" colspan="4" />
<group col="4" colspan="4">
<button special="cancel" string="Cancel" icon="gtk-cancel"/>
<button name="make_partner" string="Continue" type="object" icon="gtk-ok"/>
@@ -0,0 +1,191 @@
# -*- 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'
_description = 'Phonecall to Partner'
_columns = {
'action': fields.selection([('exist', 'Link to an existing partner'), \
('create', 'Create a new partner')], \
'Action', required=True),
'partner_id': fields.many2one('res.partner', 'Partner')
}
def _select_partner(self, cr, uid, context=None):
"""
This function Searches for Partner from selected phonecall.
@param self: The object pointer
@param cr: the current row, from the database cursor,
@param uid: the current user’s ID for security checks,
@param fields: List of fields for default value
@param context: A standard dictionary for contextual values
@return : Partner id if any for selected phonecall.
"""
if not context:
context = {}
phonecall_obj = self.pool.get('crm.phonecall')
partner_obj = self.pool.get('res.partner')
contact_obj = self.pool.get('res.partner.address')
rec_ids = context and context.get('active_ids', [])
value = {}
for phonecall in phonecall_obj.browse(cr, uid, rec_ids, context=context):
if phonecall.partner_id:
raise osv.except_osv(_('Warning !'),
_('A partner is already defined on this phonecall.'))
partner_ids = partner_obj.search(cr, uid, [('name', '=', phonecall.name or phonecall.name)])
if not partner_ids and phonecall.email_from:
address_ids = contact_obj.search(cr, uid, [('email', '=', phonecall.email_from)])
if address_ids:
addresses = contact_obj.browse(cr, uid, address_ids)
partner_ids = addresses and [addresses[0].partner_id.id] or False
partner_id = partner_ids and partner_ids[0] or False
return partner_id
_defaults = {
'action': lambda *a:'exist',
'partner_id': _select_partner
}
def open_create_partner(self, cr, uid, ids, context=None):
"""
This function Opens form of create partner.
@param self: The object pointer
@param cr: the current row, from the database cursor,
@param uid: the current user’s ID for security checks,
@param ids: List of Phonecall to Partner's IDs
@param context: A standard dictionary for contextual values
@return : Dictionary value for next form.
"""
if not context:
context = {}
view_obj = self.pool.get('ir.ui.view')
view_id = view_obj.search(cr, uid, [('model', '=', 'crm.phonecall2partner'), \
('name', '=', 'crm.phonecall2partner.view')])
return {
'view_mode': 'form',
'view_type': 'form',
'view_id': view_id or False,
'res_model': 'crm.phonecall2partner',
'context': context,
'type': 'ir.actions.act_window',
'target': 'new',
}
def _create_partner(self, cr, uid, ids, context=None):
"""
This function Creates partner based on action.
@param self: The object pointer
@param cr: the current row, from the database cursor,
@param uid: the current user’s ID for security checks,
@param ids: List of Phonecall to Partner's IDs
@param context: A standard dictionary for contextual values
@return : Dictionary {}.
"""
if not context:
context = {}
phonecall_obj = self.pool.get('crm.phonecall')
partner_obj = self.pool.get('res.partner')
contact_obj = self.pool.get('res.partner.address')
partner_ids = []
contact_id = False
rec_ids = context and context.get('active_ids', [])
for data in self.browse(cr, uid, ids):
for phonecall in phonecall_obj.browse(cr, uid, rec_ids):
if data.action == 'create':
partner_id = partner_obj.create(cr, uid, {
'name': phonecall.name or phonecall.name,
'user_id': phonecall.user_id.id,
'comment': phonecall.description,
})
contact_id = contact_obj.create(cr, uid, {
'partner_id': partner_id,
'name': phonecall.name,
'phone': phonecall.partner_phone,
})
else:
if data.partner_id:
partner_id = data.partner_id.id
contact_id = partner_obj.address_get(cr, uid, [partner_id])['default']
partner_ids.append(partner_id)
vals = {}
if partner_id:
vals.update({'partner_id': partner_id})
if contact_id:
vals.update({'partner_address_id': contact_id})
phonecall_obj.write(cr, uid, [phonecall.id], vals)
return partner_ids
def make_partner(self, cr, uid, ids, context=None):
"""
This function Makes partner based on action.
@param self: The object pointer
@param cr: the current row, from the database cursor,
@param uid: the current user’s ID for security checks,
@param ids: List of Phonecall to Partner's IDs
@param context: A standard dictionary for contextual values
@return : Dictionary value for created Partner form.
"""
if not context:
context = {}
partner_ids = self._create_partner(cr, uid, ids, context)
mod_obj = self.pool.get('ir.model.data')
result = mod_obj._get_id(cr, uid, 'base', 'view_res_partner_filter')
res = mod_obj.read(cr, uid, result, ['res_id'])
value = {
'domain': "[]",
'view_type': 'form',
'view_mode': 'form,tree',
'res_model': 'res.partner',
'res_id': partner_ids and int(partner_ids[0]) or False,
'view_id': False,
'context': context,
'type': 'ir.actions.act_window',
'search_view_id': res['res_id']
}
return value
crm_phonecall2partner()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
@@ -0,0 +1,53 @@
<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="type">form</field>
<field name="arch" type="xml">
<form string="Create a Partner">
<label string="Are you sure you want to create a partner based on this Phonecall ?" colspan="4"/>
<label string="You may have to verify that this partner does not exist already." colspan="4"/>
<separator string="" colspan="4" />
<group col="4" colspan="4">
<button special="cancel" string="Cancel" icon="gtk-cancel"/>
<button name="open_create_partner" string="Create Partner" type="object" icon="gtk-ok"/>
</group>
</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="type">form</field>
<field name="arch" type="xml">
<form string="Create a Partner">
<field name="action"/>
<group attrs="{'invisible':[('action','!=','exist')]}">
<field name="partner_id"/>
</group>
<separator string="" colspan="4" />
<group col="4" colspan="4">
<button special="cancel" string="Cancel" icon="gtk-cancel"/>
<button name="make_partner" string="Continue" type="object" icon="gtk-ok"/>
</group>
</form>
</field>
</record>
<!-- Phonecall to Partner wizard -->
<act_window id="action_crm_phonecall2partner"
key2="client_action_multi" name="Create a Partner"
res_model="crm.phonecall2partner" src_model="crm.phonecall"
view_id="view_crm_phonecall2partner_create"
view_mode="form" target="new" view_type="form" />
</data>
</openerp>
-134
View File
@@ -1,134 +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 mx.DateTime import now
from osv import osv, fields
import netsvc
import ir
import pooler
from tools.translate import _
class crm_phonecall2partner(osv.osv_memory):
_name = 'crm.phonecall2partner'
_description = 'Phone Call to Partner'
_columns = {
'action': fields.selection([('exist','Link to an existing partner'),('create','Create a new partner')],'Action',required=True),
'partner_id': fields.many2one('res.partner','Partner'),
}
_defaults = {
'action': lambda *a:'exist',
}
def create_partner(self, cr, uid, ids, context):
view_obj = self.pool.get('ir.ui.view')
view_id = view_obj.search(cr,uid,[('model','=','crm.phonecall2partner'),('name','=','crm.phonecall2partner.view')])
return {
'view_mode': 'form',
'view_type': 'form',
'view_id': view_id or False,
'res_model': 'crm.phonecall2partner',
'type': 'ir.actions.act_window',
'target': 'new',
}
def selectPartner(self, cr, uid, ids, context):
case_obj = self.pool.get('crm.phonecall')
partner_obj = self.pool.get('res.partner')
contact_obj = self.pool.get('res.partner.address')
rec_ids = context and context.get('record_ids',False)
value={}
for case in case_obj.browse(cr, uid, rec_ids):
if case.partner_id:
raise osv.except_osv(_('Warning !'),
_('A partner is already defined on this lead.'))
partner_ids = partner_obj.search(cr, uid, [('name', '=', case.partner_contact or case.name)])
if not partner_ids and case.email_from:
address_ids = contact_obj.search(cr, uid, [('email', '=', case.email_from)])
if address_ids:
addresses = contact_obj.browse(cr, uid, address_ids)
partner_ids = addresses and [addresses[0].partner_id.id] or False
partner_id = partner_ids and partner_ids[0] or False
if not partner_id:
value = self._make_partner(cr, uid, ids, context)
return value
def _create_partner(self, cr, uid, ids, context):
case_obj = self.pool.get('crm.phonecall')
partner_obj = self.pool.get('res.partner')
contact_obj = self.pool.get('res.partner.address')
datas = self.browse(cr, uid, ids)[0]
partner_ids = []
partner_id = False
contact_id = False
rec_ids = context and context.get('record_ids',False)
for case in case_obj.browse(cr, uid, rec_ids):
if datas.action == 'create':
partner_id = partner_obj.create(cr, uid, {
'name': case.partner_contact or case.name,
'user_id': case.user_id.id,
'comment': case.description,
})
contact_id = contact_obj.create(cr, uid, {
'partner_id': partner_id,
'name': case.name,
'phone': case.partner_phone,
'mobile': case.partner_mobile,
'email': case.email_from
})
else:
if datas.partner_id:
partner = partner_obj.browse(cr,uid,datas.partner_id.id)
partner_id = partner.id
contact_id = partner.address and partner.address[0].id
partner_ids.append(partner_id)
vals = {}
if partner_id:
vals.update({'partner_id': partner_id})
if contact_id:
vals.update({'partner_address_id': contact_id})
case_obj.write(cr, uid, [case.id], vals)
return partner_ids
def _make_partner(self, cr, uid, ids, context):
partner_ids = self._create_partner(cr, uid, ids, context)
mod_obj = self.pool.get('ir.model.data')
result = mod_obj._get_id(cr, uid, 'base', 'view_res_partner_filter')
res = mod_obj.read(cr, uid, result, ['res_id'])
value = {
'domain': "[]",
'view_type': 'form',
'view_mode': 'form,tree',
'res_model': 'res.partner',
'res_id': partner_ids and int(partner_ids[0]) or False,
'view_id': False,
'type': 'ir.actions.act_window',
'search_view_id': res['res_id']
}
return value
crm_phonecall2partner()
@@ -1,67 +0,0 @@
<openerp>
<data>
<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="type">form</field>
<field name="arch" type="xml">
<form string="Create a Partner">
<label string="Are you sure you want to create a partner based on this lead ?" colspan="4"/>
<label string="You may have to verify that this partner does not exist already." colspan="4"/>
<group col="4" colspan="4">
<button special="cancel" string="Cancel" icon="gtk-cancel"/>
<button name="create_partner" string="Create Partner" type="object" icon="gtk-ok"/>
</group>
</form>
</field>
</record>
<record id="action_crm_phonecall2partner_create" 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_id" ref="view_crm_lead2partner_create"/>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="target">new</field>
<field name="context">{'record_ids' : active_ids}</field>
</record>
<record model="ir.values" id="values_crm_phonecall2partner_create">
<field name="model_id" ref="crm.model_crm_lead" />
<field name="object" eval="1" />
<field name="name">Create Partner</field>
<field name="key2">client_action_multi</field>
<field name="value" eval="'ir.actions.act_window,' + str(ref('action_crm_phonecall2partner_create'))" />
<field name="key">action</field>
<field name="model">crm.phonecall</field>
</record>
<record id="view_crm_phonecall2partner" model="ir.ui.view">
<field name="name">crm.phonecall2partner.view</field>
<field name="model">crm.phonecall2partner</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Create a Partner">
<field name="action"/>
<group attrs="{'invisible':[('action','!=','exist')]}">
<field name="partner_id"/>
</group>
<group col="4" colspan="4">
<button special="cancel" string="Cancel" icon="gtk-cancel"/>
<button name="selectPartner" string="Continue" type="object" icon="gtk-ok"/>
</group>
</form>
</field>
</record>
<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_id" ref="view_crm_phonecall2partner"/>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="target">new</field>
<field name="context">{'record_ids' : active_ids}</field>
</record>
</data>
</openerp>