[FIX] email_template :
- fixed composer using template that were rendering the body twice, once form the template and once from the composer body. Only the latter one is used, so avoid generating the template body that is not necessary - fixed email_template generating values for a set of given fields, ignoring the field list given into parameter - fixed post processing of templates to transform local urls into absolute urls; now urls are transformed after body generation, when sending email based on templates , or when generating the content when using the composer. bzr revid: tde@openerp.com-20140227153835-gmqnxrzed9fnbxhm
This commit is contained in:
parent
b1f88d634d
commit
a9a4767d17
|
@ -356,17 +356,17 @@ class email_template(osv.osv):
|
|||
results = dict()
|
||||
for template, template_res_ids in templates_to_res_ids.iteritems():
|
||||
# generate fields value for all res_ids linked to the current template
|
||||
for field in ['subject', 'body_html', 'email_from', 'email_to', 'partner_to', 'email_cc', 'reply_to']:
|
||||
for field in fields:
|
||||
generated_field_values = self.render_template_batch(cr, uid, getattr(template, field), template.model, template_res_ids, context=context)
|
||||
for res_id, field_value in generated_field_values.iteritems():
|
||||
results.setdefault(res_id, dict())[field] = field_value
|
||||
# update values for all res_ids
|
||||
for res_id in template_res_ids:
|
||||
values = results[res_id]
|
||||
if template.user_signature:
|
||||
if 'body_html' in fields and template.user_signature:
|
||||
signature = self.pool.get('res.users').browse(cr, uid, uid, context).signature
|
||||
values['body_html'] = tools.append_content_to_html(values['body_html'], signature)
|
||||
if values['body_html']:
|
||||
if values.get('body_html'):
|
||||
values['body'] = tools.html_sanitize(values['body_html'])
|
||||
values.update(
|
||||
mail_server_id=template.mail_server_id.id or False,
|
||||
|
|
|
@ -162,16 +162,18 @@ class mail_compose_message(osv.TransientModel):
|
|||
partner_ids += self.pool['res.partner'].exists(cr, SUPERUSER_ID, tpl_partner_ids, context=context)
|
||||
return partner_ids
|
||||
|
||||
def generate_email_for_composer_batch(self, cr, uid, template_id, res_ids, context=None):
|
||||
def generate_email_for_composer_batch(self, cr, uid, template_id, res_ids, context=None, fields=None):
|
||||
""" Call email_template.generate_email(), get fields relevant for
|
||||
mail.compose.message, transform email_cc and email_to into partner_ids """
|
||||
# filter template values
|
||||
fields = ['subject', 'body_html', 'email_from', 'email_to', 'partner_to', 'email_cc', 'reply_to', 'attachment_ids', 'attachments', 'mail_server_id']
|
||||
if fields is None:
|
||||
fields = ['subject', 'body_html', 'email_from', 'email_to', 'partner_to', 'email_cc', 'reply_to', 'attachment_ids', 'mail_server_id']
|
||||
returned_fields = fields + ['attachments']
|
||||
values = dict.fromkeys(res_ids, False)
|
||||
|
||||
template_values = self.pool.get('email.template').generate_email_batch(cr, uid, template_id, res_ids, context=context)
|
||||
template_values = self.pool.get('email.template').generate_email_batch(cr, uid, template_id, res_ids, fields=fields, context=context)
|
||||
for res_id in res_ids:
|
||||
res_id_values = dict((field, template_values[res_id][field]) for field in fields if template_values[res_id].get(field))
|
||||
res_id_values = dict((field, template_values[res_id][field]) for field in returned_fields if template_values[res_id].get(field))
|
||||
res_id_values['body'] = res_id_values.pop('body_html', '')
|
||||
|
||||
# transform email_to, email_cc into partner_ids
|
||||
|
@ -189,7 +191,10 @@ class mail_compose_message(osv.TransientModel):
|
|||
""" Override to handle templates. """
|
||||
# generate template-based values
|
||||
if wizard.template_id:
|
||||
template_values = self.generate_email_for_composer_batch(cr, uid, wizard.template_id.id, res_ids, context=context)
|
||||
template_values = self.generate_email_for_composer_batch(
|
||||
cr, uid, wizard.template_id.id, res_ids,
|
||||
fields=['email_to', 'partner_to', 'email_cc', 'attachment_ids', 'mail_server_id'],
|
||||
context=context)
|
||||
else:
|
||||
template_values = dict.fromkeys(res_ids, dict())
|
||||
# generate composer values
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import mail_message
|
||||
import mail_thread
|
||||
import email_template
|
||||
import mail_compose_message
|
|
@ -79,12 +79,10 @@ class EmailTemplate(osv.Model):
|
|||
html = html[5:-6]
|
||||
return html
|
||||
|
||||
def create(self, cr, uid, values, context=None):
|
||||
if 'body_html' in values:
|
||||
values['body_html'] = self._postprocess_html_replace_links(cr, uid, values['body_html'], context=context)
|
||||
return super(EmailTemplate, self).create(cr, uid, values, context=context)
|
||||
|
||||
def write(self, cr, uid, ids, values, context=None):
|
||||
if 'body_html' in values:
|
||||
values['body_html'] = self._postprocess_html_replace_links(cr, uid, values['body_html'], context=context)
|
||||
return super(EmailTemplate, self).write(cr, uid, ids, values, context=context)
|
||||
def generate_email_batch(self, cr, uid, template_id, res_ids, context=None, fields=None):
|
||||
""" Add a post processing after rendering, aka replace local URLs to absolute URLs. """
|
||||
results = super(EmailTemplate, self).generate_email_batch(cr, uid, template_id, res_ids, context=context, fields=fields)
|
||||
for res_id, value in results.iteritems():
|
||||
if 'body_html' in value:
|
||||
results[res_id]['body_html'] = self._postprocess_html_replace_links(cr, uid, value['body_html'], context=context)
|
||||
return results
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# Copyright (C) 2014-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 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 openerp.osv import osv
|
||||
|
||||
|
||||
class MailComposeMessage(osv.Model):
|
||||
_inherit = 'mail.compose.message'
|
||||
|
||||
def generate_email_for_composer_batch(self, cr, uid, template_id, res_ids, context=None, fields=None):
|
||||
""" Add a post processing after rendering, aka replace local URLs to absolute URLs. """
|
||||
results = super(MailComposeMessage, self).generate_email_for_composer_batch(cr, uid, template_id, res_ids, context=context, fields=fields)
|
||||
for res_id, value in results.iteritems():
|
||||
if 'body' in value:
|
||||
results[res_id]['body'] = self.pool['email.template']._postprocess_html_replace_links(cr, uid, value['body'], context=context)
|
||||
return results
|
Loading…
Reference in New Issue