diff --git a/addons/email_template/__openerp__.py b/addons/email_template/__openerp__.py index 2f21631b7d7..fb89261f516 100644 --- a/addons/email_template/__openerp__.py +++ b/addons/email_template/__openerp__.py @@ -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, diff --git a/addons/email_template/email_template.py b/addons/email_template/email_template.py index 59025fa5162..0823638c614 100644 --- a/addons/email_template/email_template.py +++ b/addons/email_template/email_template.py @@ -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 = [ diff --git a/addons/email_template/wizard/__init__.py b/addons/email_template/wizard/__init__.py index 006106a0263..1bac2d4aaad 100644 --- a/addons/email_template/wizard/__init__.py +++ b/addons/email_template/wizard/__init__.py @@ -21,4 +21,5 @@ ############################################################################## import email_template_preview import email_template_send_wizard +import email_compose_message diff --git a/addons/email_template/wizard/email_compose_message.py b/addons/email_template/wizard/email_compose_message.py new file mode 100644 index 00000000000..c18ad815b66 --- /dev/null +++ b/addons/email_template/wizard/email_compose_message.py @@ -0,0 +1,83 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2010-Today OpenERP SA () +# +# 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 +# +############################################################################## + +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: diff --git a/addons/email_template/wizard/email_compose_message_view.xml b/addons/email_template/wizard/email_compose_message_view.xml new file mode 100644 index 00000000000..0daf7680d86 --- /dev/null +++ b/addons/email_template/wizard/email_compose_message_view.xml @@ -0,0 +1,21 @@ + + + + + + email.compose.message.form + email.compose.message + form + + + + + + + + + + diff --git a/addons/emails/wizard/email_compose_message.py b/addons/emails/wizard/email_compose_message.py index 184677d29ba..c93a9c884b5 100644 --- a/addons/emails/wizard/email_compose_message.py +++ b/addons/emails/wizard/email_compose_message.py @@ -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 diff --git a/addons/emails/wizard/email_compose_message_view.xml b/addons/emails/wizard/email_compose_message_view.xml index 091888f3508..52860e15c67 100644 --- a/addons/emails/wizard/email_compose_message_view.xml +++ b/addons/emails/wizard/email_compose_message_view.xml @@ -10,14 +10,14 @@
- - + +