[ADD] email_template :- inherit email.compose.message wizard and add template_id field. on template_id field get template and change the value of wizard.

bzr revid: ysa@tinyerp.com-20110223092708-aibiuj5ojw41y6ky
This commit is contained in:
Yogesh (OpenERP) 2011-02-23 14:57:08 +05:30
parent c4352d9801
commit 30bde91c88
7 changed files with 121 additions and 7 deletions

View File

@ -36,6 +36,7 @@
'wizard/email_template_preview_view.xml',
'email_template_view.xml',
'wizard/email_template_send_wizard_view.xml',
'wizard/email_compose_message_view.xml',
'security/ir.model.access.csv'
],
"installable": True,

View File

@ -168,6 +168,7 @@ This is useful for CRM leads for example"),
" body for displaying the info in your mail.",
store=False),
'auto_delete': fields.boolean('Auto Delete', help="Permanently delete emails after sending"),
'model': fields.related('model_id','model', type='char', size=128, string='Object'),
}
_sql_constraints = [

View File

@ -21,4 +21,5 @@
##############################################################################
import email_template_preview
import email_template_send_wizard
import email_compose_message

View File

@ -0,0 +1,83 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2010-Today OpenERP SA (<http://www.openerp.com>)
#
# 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
from osv import fields
import tools
class email_compose_message(osv.osv_memory):
_name = 'email.compose.message'
_inherit = 'email.compose.message'
def _get_templates(self, cr, uid, context=None):
"""
Return Email Template of particular Model.
"""
if context is None:
context = {}
record_ids = []
email_temp_pool = self.pool.get('email.template')
model = False
if context.get('email_model',False):
model = context.get('email_model')
elif context.get('active_model',False):
model = context.get('active_model')
if model:
record_ids = email_temp_pool.search(cr, uid, [('model','=',model)])
return email_temp_pool.name_get(cr, uid, record_ids, context)
return []
_columns = {
'template_id': fields.selection(_get_templates, 'Template'),
}
def on_change_template(self, cr, uid, ids, model, resource_id, template_id, context=None):
if context is None:
context = {}
email_temp_previ_pool = self.pool.get('email_template.preview')
result = self.on_change_referred_doc(cr, uid, [], model, resource_id, context=context)
vals = result.get('value',{})
if template_id and resource_id:
context.update({'template_id': template_id})
value = email_temp_previ_pool.on_change_ref(cr, uid, [], resource_id, context)
new_value = value.get('value',{})
if vals.get('email_from'):
new_value.get('email_from') and new_value.update({'email_from': new_value.get('email_from') + ',' + vals.get('email_from')}) or vals.get('email_from')
if vals.get('email_to'):
new_value.update({'email_to': new_value.get('email_to') + ',' + vals.get('email_to')}) or vals.get('email_to')
if vals.get('email_cc'):
new_value.get('email_cc') and new_value.update({'email_cc': new_value.get('email_cc') + ',' + vals.get('email_cc')}) or vals.get('email_cc')
if vals.get('email_bcc'):
new_value.get('email_bcc') and new_value.update({'email_bcc': new_value.get('email_bcc') + ',' + vals.get('email_bcc')}) or vals.get('email_bcc')
if vals.get('reply_to'):
new_value.get('reply_to') and new_value.update({'reply_to': new_value.get('reply_to') + ',' + vals.get('reply_to')}) or vals.get('reply_to')
vals.update(new_value)
vals.update({'name': new_value.get('subject','')})
return {'value': vals}
email_compose_message()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record model="ir.ui.view" id="email_compose_message_wizard_inherit_form">
<field name="name">email.compose.message.form</field>
<field name="model">email.compose.message</field>
<field name="type">form</field>
<field name="inherit_id" ref="emails.email_compose_message_wizard_form"/>
<field name="arch" type="xml">
<field name="res_id" position="replace">
<field name="template_id" colspan="4"
on_change="on_change_template(model, res_id, template_id)"/>
<field name="res_id"
invisible="context.get('active_model','') != 'ir.ui.menu'"
colspan="4" on_change="on_change_template(model, res_id, template_id)"/>
</field>
</field>
</record>
</data>
</openerp>

View File

@ -111,16 +111,23 @@ class email_compose_message(osv.osv_memory):
if context is None:
context = {}
record_ids = []
model_pool = False
if context.get('email_model',False):
model_pool = self.pool.get(context.get('email_model'))
model = context.get('email_model')
model_pool = self.pool.get(model)
record_ids = model_pool.search(cr, uid, [])
elif context.get('active_model',False):
model = context.get('active_model')
model_pool = self.pool.get(model)
record_ids = context.get('active_ids',[])
if model_pool:
return model_pool.name_get(cr, uid, record_ids, context)
return record_ids
return []
_columns = {
'attachment_ids': fields.many2many('ir.attachment','email_message_send_attachment_rel', 'wizard_id', 'attachment_id', 'Attachments'),
'debug':fields.boolean('Debug', readonly=True),
'resource_id':fields.selection(_get_records, 'Referred Document'),
'res_id':fields.selection(_get_records, 'Referred Document'),
}
def on_change_referred_doc(self, cr, uid, ids, model, resource_id, context=None):
@ -148,7 +155,7 @@ class email_compose_message(osv.osv_memory):
attachment.append((attach.datas_fname, attach.datas))
email_id = email_message_pool.email_send(cr, uid, mail.email_from, mail.email_to, mail.name, mail.description,
model=mail.model, email_cc=mail.email_cc, email_bcc=mail.email_bcc, reply_to=mail.reply_to,
attach=attachment, message_id=mail.message_id, openobject_id=mail.res_id, debug=mail.debug,
attach=attachment, message_id=mail.message_id, openobject_id=int(mail.res_id), debug=mail.debug,
subtype=mail.sub_type, x_headers=mail.headers, priority=mail.priority, smtp_server_id=mail.smtp_server_id and mail.smtp_server_id.id, context=context)
email_ids.append(email_id)
return email_ids

View File

@ -10,14 +10,14 @@
<form string="Reply Email">
<group col="6" colspan="4">
<field name="model" invisible="1"/>
<field name="resource_id" invisible="context.get('active_model','') != 'ir.ui.menu'"
colspan="4" on_change="on_change_referred_doc(model, resource_id)"/>
<field name="res_id" invisible="1"/>
<field name="res_id" invisible="context.get('active_model','') != 'ir.ui.menu'"
colspan="4" on_change="on_change_referred_doc(model, res_id)"/>
<field name="smtp_server_id" widget="selection" colspan="4"/>
<field name="email_from" colspan="4" required="1"/>
<field name="email_to" colspan="4" required="1"/>
<field name="email_cc" colspan="4"/>
<field name="email_bcc" colspan="4"/>
<field name="reply_to" colspan="4"/>
<field name="name" colspan="4" widget="char" size="512"/>
</group>
<separator string="" colspan="4"/>