crm: add the missing file and add the wizard of opportunity2phonecall

bzr revid: sbh@tinyerp.com-20100310054717-taqd558s8p75hinr
This commit is contained in:
sbh (Open ERP) 2010-03-10 11:17:17 +05:30
parent 97837a5537
commit 5324e660c1
9 changed files with 381 additions and 2 deletions

View File

@ -68,6 +68,7 @@ between mails and Open ERP.""",
'wizard/phonecall2opportunity.xml',
'wizard/opportunity2partner_view.xml',
'wizard/opportunity2meeting.xml',
'wizard/opportunity2phonecall.xml',
'crm_wizard.xml',
'crm_view.xml',

View File

@ -34,6 +34,7 @@ import phonecall2meeting
import phonecall_to_opportunity
import opportunity2partner
import opportunity2meeting
import opportunity2phonecall
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -0,0 +1,31 @@
<?xml version="1.0"?>
<openerp>
<data>
<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">
<field name="name"/>
<field name="user_id" />
<field name="date" string="Planned Date"/>
<field name="section_id"/>
<group colspan="2" col="2" >
<button name="action_cancel" string="_Cancel" icon="gtk-cancel" special="cancel" />
<button name="action_apply" type="object" string="_Apply" icon="gtk-apply" />
</group>
</form>
</field>
</record>
<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>
<field name="view_type">form</field>
<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,143 @@
# -*- 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_lead2partner(osv.osv_memory):
_name = 'crm.lead2partner'
_description = 'Lead 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.lead2partner'),('name','=','crm.lead2partner.view')])
return {
'view_mode': 'form',
'view_type': 'form',
'view_id': view_id or False,
'res_model': 'crm.lead2partner',
'type': 'ir.actions.act_window',
'target': 'new',
}
def selectPartner(self, cr, uid, ids, context):
case_obj = self.pool.get('crm.lead')
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_name 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.lead')
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_name 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.phone,
'mobile': case.mobile,
'email': case.email_from,
'fax': case.fax,
'title': case.title,
'function': case.function and case.function.id or False,
'street': case.street,
'street2': case.street2,
'zip': case.zip,
'city': case.city,
'country_id': case.country_id and case.country_id.id or False,
'state_id': case.state_id and case.state_id.id or False,
})
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_lead2partner()

View File

@ -0,0 +1,67 @@
<openerp>
<data>
<record id="view_crm_lead2partner_create" model="ir.ui.view">
<field name="name">crm.lead2partner.view.create</field>
<field name="model">crm.lead2partner</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_lead2partner_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.lead2partner</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_lead2partner_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_lead2partner_create'))" />
<field name="key">action</field>
<field name="model">crm.lead</field>
</record>
<record id="view_crm_lead2partner" model="ir.ui.view">
<field name="name">crm.lead2partner.view</field>
<field name="model">crm.lead2partner</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_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_id" ref="view_crm_lead2partner"/>
<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>

View File

@ -38,7 +38,7 @@ class crm_opportunity2meeting(osv.osv_memory):
def action_cancel(self, cr, uid, ids, context=None):
return {'type':'ir.actions.act_window_close'}
def _makeMeeting(self, cr, uid, ids, context=None):
def action_makeMeeting(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:

View File

@ -8,7 +8,7 @@
<field name="arch" type="xml">
<form string="Convert To Meeting ">
<button name="action_cancel" string="_Cancel" icon="gtk-cancel" special="cancel" />
<button name="_makeMeeting" type="object" string="_Apply" icon="gtk-apply" />
<button name="action_makeMeeting" type="object" string="_Apply" icon="gtk-apply" />
</form>
</field>
</record>

View File

@ -0,0 +1,105 @@
# -*- 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_opportunity2phonecall(osv.osv_memory):
_name = 'crm.opportunity2phonecall'
_description = 'Opportunity to Phonecall'
_columns = {
'name' : fields.char('Call summary', size=64, required=True, select=1),
'user_id' : fields.many2one('res.users',"Assign To"),
'date': fields.datetime('Date' ,required=True),
'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_opportunity2phonecall, self).default_get(cr, uid, fields, context=context)
if record_id:
opportunity = self.pool.get('crm.opportunity').browse(cr, uid, record_id, context=context)
res['name']=opportunity.name
res['user_id']=opportunity.user_id and opportunity.user_id.id or False
res['section_id']=opportunity.section_id and opportunity.section_id.id or False
return res
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)
mod_obj =self.pool.get('ir.model.data')
result = mod_obj._get_id(cr, uid, 'crm', 'view_crm_case_phonecalls_filter')
res = mod_obj.read(cr, uid, result, ['res_id'])
phonecall_case_obj = self.pool.get('crm.phonecall')
opportunity_case_obj = self.pool.get('crm.opportunity')
# Select the view
record_id = context and context.get('record_id', False) or False
data_obj = self.pool.get('ir.model.data')
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:
id2 = data_obj.browse(cr, uid, id2, context=context).res_id
if id3:
id3 = data_obj.browse(cr, uid, id3, context=context).res_id
opportunites = opportunity_case_obj.browse(cr, uid, [record_id])
for opportunity in opportunites:
new_case = phonecall_case_obj.create(cr, uid, {
'name' : opportunity.name,
'case_id' : opportunity.id,
'user_id' : this.user_id,
'categ_id' : opportunity.categ_id,
'description' : opportunity.description,
'date' : this.date,
'section_id' : opportunity.section_id and opportunity.section_id.id or False,
'partner_id': opportunity.partner_id and opportunity.partner_id.id or False,
'partner_address_id':opportunity.partner_address_id and opportunity.partner_address_id.id or False,
'description': opportunity.description or '',
'partner_phone' : opportunity.phone or (opportunity.partner_address_id and opportunity.partner_address_id.phone or False),
'partner_mobile' : opportunity.partner_address_id and opportunity.partner_address_id.mobile or False,
'priority': opportunity.priority,
'opportunity_id':opportunity.id
}, context=context)
vals = {}
phonecall_case_obj.case_open(cr, uid, [new_case])
value = {
'name': _('Phone Call'),
'view_type': 'form',
'view_mode': 'tree,form',
'res_model': 'crm.phonecall',
'res_id' : new_case,
'views': [(id3,'form'),(id2,'tree'),(False,'calendar'),(False,'graph')],
'type': 'ir.actions.act_window',
'search_view_id': res['res_id']
}
return value
crm_opportunity2phonecall()

View File

@ -0,0 +1,31 @@
<?xml version="1.0"?>
<openerp>
<data>
<record model="ir.ui.view" id="opportunity2phonecall_view">
<field name="name">crm.opportunity2phonecall.form</field>
<field name="model">crm.opportunity2phonecall</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Schedule Other Call" col="2">
<field name="name"/>
<field name="user_id" />
<field name="date" string="Planned Date"/>
<field name="section_id"/>
<group colspan="2" col="2" >
<button name="action_cancel" string="_Cancel" icon="gtk-cancel" special="cancel" />
<button name="action_apply" type="object" string="_Apply" icon="gtk-apply" />
</group>
</form>
</field>
</record>
<record model="ir.actions.act_window" id="opportunity2phonecall_act">
<field name="name">Schedule Other Call</field>
<field name="res_model">crm.opportunity2phonecall</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="view_id" ref="opportunity2phonecall_view"/>
<field name="target">new</field>
<field name="context">{'record_id' : active_id}</field>
</record>
</data>
</openerp>