[IMP] crm: Allow to an user to forward a lead to a partner
bzr revid: stephane@openerp.com-20100428115222-kjs3gikx24eztjo1
This commit is contained in:
parent
54b33326a8
commit
714fdc0f98
|
@ -75,6 +75,7 @@ between mails and Open ERP.""",
|
|||
'wizard/crm_opportunity_to_phonecall_view.xml',
|
||||
'wizard/crm_partner_to_opportunity_view.xml',
|
||||
|
||||
'wizard/crm_forward_to_partner_view.xml',
|
||||
'wizard/crm_send_email_view.xml',
|
||||
'wizard/crm_email_add_cc_view.xml',
|
||||
'crm_view.xml',
|
||||
|
|
|
@ -174,15 +174,20 @@
|
|||
icon="gtk-undo" type="action" />
|
||||
</form>
|
||||
<tree string="Communication history">
|
||||
<field name="description"/>
|
||||
<field name="email_to"/>
|
||||
<field name="name" />
|
||||
<field name="date"/>
|
||||
<field name="email_from" />
|
||||
<field name="email_to"/>
|
||||
<field name="description"/>
|
||||
</tree>
|
||||
</field>
|
||||
<button colspan="4" string="Send New Email"
|
||||
<button colspan="2" string="Send New Email"
|
||||
name="%(action_crm_send_mail)d"
|
||||
context="{'mail':'new', 'model': 'crm.lead'}"
|
||||
icon="gtk-go-forward" type="action" />
|
||||
<button colspan="2" string="Forward to Partner"
|
||||
name="%(crm_lead_forward_to_partner_act)d"
|
||||
icon="gtk-go-forward" type="action" />
|
||||
</page>
|
||||
|
||||
</notebook>
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
##############################################################################
|
||||
|
||||
import crm_send_email
|
||||
import crm_forward_to_partner
|
||||
import crm_email_add_cc
|
||||
|
||||
import crm_lead_to_partner
|
||||
|
|
|
@ -0,0 +1,160 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>). 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
|
||||
|
||||
from tools.translate import _
|
||||
import tools
|
||||
|
||||
class crm_lead_forward_to_partner(osv.osv_memory):
|
||||
_name = 'crm.lead.forward.to.partner'
|
||||
|
||||
_columns = {
|
||||
'partner_id' : fields.many2one('res.partner', 'Partner'),
|
||||
'address_id' : fields.many2one('res.partner.address', 'Address'),
|
||||
'email_from' : fields.char('From', required=True, size=128),
|
||||
'email_to' : fields.char('To', required=True, size=128),
|
||||
'subject' : fields.char('Subject', required=True, size=128),
|
||||
'message' : fields.text('Message', required=True),
|
||||
}
|
||||
|
||||
def on_change_partner(self, cr, uid, ids, partner_id):
|
||||
return {
|
||||
'domain' : {
|
||||
'address_id' : partner_id and "[('partner_id', '=', partner_id)]" or "[]",
|
||||
}
|
||||
}
|
||||
|
||||
def on_change_address(self, cr, uid, ids, address_id):
|
||||
email = ''
|
||||
if address_id:
|
||||
email = self.pool.get('res.partner.address').browse(cr, uid, address_id).email
|
||||
|
||||
return {
|
||||
'value' : {
|
||||
'email_to' : email,
|
||||
}
|
||||
}
|
||||
|
||||
def action_cancel(self, cr, uid, ids, context=None):
|
||||
return {'type' : 'ir.actions.act_window_close'}
|
||||
|
||||
def action_forward(self, cr, uid, ids, context=None):
|
||||
"""
|
||||
Forward the lead to a partner
|
||||
"""
|
||||
if context is None:
|
||||
context = {}
|
||||
|
||||
res_id = context.get('active_id', False)
|
||||
|
||||
if not res_id:
|
||||
return {}
|
||||
|
||||
this = self.browse(cr, uid, ids[0], context=context)
|
||||
|
||||
hist_obj = self.pool.get('crm.case.history')
|
||||
smtp_pool = self.pool.get('email.smtpclient')
|
||||
case_pool = self.pool.get('crm.lead')
|
||||
case = case_pool.browse(cr, uid, res_id, context=context)
|
||||
|
||||
emails = [this.email_to]
|
||||
body = case_pool.format_body(this.message)
|
||||
email_from = this.email_from or False
|
||||
case_pool._history(cr, uid, [case], _('Forward'), history=True, email=this.email_to, details=body, email_from=email_from)
|
||||
|
||||
flag = False
|
||||
if case.section_id and case.section_id.server_id:
|
||||
flag = smtp_pool.send_email(
|
||||
cr=cr,
|
||||
uid=uid,
|
||||
server_id=case.section_id.server_id.id,
|
||||
emailto=emails,
|
||||
subject=this.subject,
|
||||
body="<pre>%s</pre>" % body,
|
||||
)
|
||||
else:
|
||||
flag = tools.email_send(
|
||||
email_from,
|
||||
emails,
|
||||
this.subject,
|
||||
body,
|
||||
)
|
||||
|
||||
return {}
|
||||
|
||||
def default_get(self, cr, uid, fields, context=None):
|
||||
"""
|
||||
This function gets default values
|
||||
"""
|
||||
if context is None:
|
||||
context = {}
|
||||
|
||||
active_ids = context.get('active_ids')
|
||||
if not active_ids:
|
||||
return {}
|
||||
|
||||
lead_proxy = self.pool.get('crm.lead')
|
||||
|
||||
lead = lead_proxy.browse(cr, uid, active_ids[0], context=context)
|
||||
|
||||
field_names = [
|
||||
'partner_name', 'title', 'function_name', 'street', 'street2',
|
||||
'zip', 'city', 'country_id', 'state_id', 'email_from',
|
||||
'phone', 'fax', 'mobile'
|
||||
]
|
||||
|
||||
message = []
|
||||
|
||||
for field_name in field_names:
|
||||
field_definition = lead_proxy._columns[field_name]
|
||||
value = None
|
||||
|
||||
if field_definition._type == 'selection':
|
||||
if hasattr(field_definition.selection, '__call__'):
|
||||
key = field_definition.selection(lead_proxy, cr, uid, context=context)
|
||||
else:
|
||||
key = field.definition.selection
|
||||
value = dict(key).get(lead[field_name], lead[field_name])
|
||||
elif field_definition._type == 'many2one':
|
||||
if lead[field_name]:
|
||||
value = lead[field_name].name_get()[0][1]
|
||||
else:
|
||||
value = lead[field_name]
|
||||
|
||||
message.append("%s: %s" % (field_definition.string, value or ''))
|
||||
|
||||
user = self.pool.get('res.users').browse(cr, uid, uid, context=context)
|
||||
email_from = ''
|
||||
if user.address_id and user.address_id.email:
|
||||
email_from = "%s <%s>" % (user.name, user.address_id.email)
|
||||
|
||||
res = {
|
||||
'email_from' : email_from,
|
||||
'subject' : '[Lead-Forward:%06d] %s' % (lead.id, lead.name),
|
||||
'message' : "\n".join(message + ['---']),
|
||||
}
|
||||
|
||||
return res
|
||||
|
||||
crm_lead_forward_to_partner()
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
|
@ -0,0 +1,38 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<openerp>
|
||||
<data>
|
||||
<record model="ir.ui.view" id="crm_lead_forward_to_partner_form">
|
||||
<field name="name">crm_lead_forward_to_partner</field>
|
||||
<field name="model">crm.lead.forward.to.partner</field>
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Forward to Partner">
|
||||
<separator string="User" colspan="4" />
|
||||
<field name="email_from" colspan="4" />
|
||||
|
||||
<separator string="Destination" colspan="4" />
|
||||
<field name="partner_id" on_change="on_change_partner(partner_id)" colspan="4" />
|
||||
<field name="address_id" string="Contact" on_change="on_change_address(address_id)" colspan="4" />
|
||||
<field name="email_to" colspan="4" />
|
||||
|
||||
<separator string="Email" colspan="4" />
|
||||
<field name="subject" colspan="4" />
|
||||
<field name="message" colspan="4" />
|
||||
<separator string="" colspan="4" />
|
||||
<group colspan="4" col="2">
|
||||
<button name="action_cancel" special="cancel" string="Cancel" icon="gtk-cancel" type="object" />
|
||||
<button name="action_forward" string="Forward" icon="gtk-go-forward" type="object" />
|
||||
</group>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.actions.act_window" id="crm_lead_forward_to_partner_act">
|
||||
<field name="name">Forward to Partner</field>
|
||||
<field name="res_model">crm.lead.forward.to.partner</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_mode">form</field>
|
||||
<field name="target">new</field>
|
||||
</record>
|
||||
</data>
|
||||
</openerp>
|
Loading…
Reference in New Issue