[FIX] email_template: keep email_from and outgoing server

When sending an email from mail.compose.message using a template, the system
should use the outgoing mail server associated to the template.
Introduce context hack to keep these values.

This should NOT to be forward ported to version 8 where a proper fix exists.

Fixes #3848
This commit is contained in:
Lorenzo Battistini 2014-11-24 18:41:08 +01:00 committed by Martin Trigaux
parent dc0e126b53
commit 0f82346167
2 changed files with 16 additions and 2 deletions

View File

@ -66,10 +66,18 @@ class mail_compose_message(osv.TransientModel):
Indeed, basic mail.compose.message wizard duplicates attachments in mass
mailing mode. But in 'single post' mode, attachments of an email template
also have to be duplicated to avoid changing their ownership. """
email_context = dict(context or {})
for wizard in self.browse(cr, uid, ids, context=context):
if not wizard.attachment_ids or wizard.composition_mode == 'mass_mail' or not wizard.template_id:
continue
template = self.pool.get('email.template').browse(cr, uid, wizard.template_id, context=context)
# TODO v8, remove me
# template specific outgoing mail server and email from is lost in super send_mail
# store them in the context to avoid falling back to default values
if template.mail_server_id:
email_context['mail_server_id'] = template.mail_server_id.id
if template.email_from:
email_context['email_from'] = template.email_from
new_attachment_ids = []
for attachment in wizard.attachment_ids:
if attachment in template.attachment_ids:
@ -77,7 +85,7 @@ class mail_compose_message(osv.TransientModel):
else:
new_attachment_ids.append(attachment.id)
self.write(cr, uid, wizard.id, {'attachment_ids': [(6, 0, new_attachment_ids)]}, context=context)
return super(mail_compose_message, self).send_mail(cr, uid, ids, context=context)
return super(mail_compose_message, self).send_mail(cr, uid, ids, context=email_context)
def onchange_template_id(self, cr, uid, ids, template_id, composition_mode, model, res_id, context=None):
""" - mass_mailing: we cannot render, so return the template values

View File

@ -156,7 +156,10 @@ class mail_notification(osv.Model):
body_html = tools.append_content_to_html(body_html, signature, plaintext=True, container_tag='div')
# email_from: partner-user alias or partner email or mail.message email_from
if msg.author_id and msg.author_id.user_ids and msg.author_id.user_ids[0].alias_domain and msg.author_id.user_ids[0].alias_name:
if 'email_from' in context:
# temporary workaround for mail from send mail wizard
email_from = context['email_from']
elif msg.author_id and msg.author_id.user_ids and msg.author_id.user_ids[0].alias_domain and msg.author_id.user_ids[0].alias_name:
email_from = formataddr((msg.author_id.name, '%s@%s' % (msg.author_id.user_ids[0].alias_name, msg.author_id.user_ids[0].alias_domain)))
elif msg.author_id:
email_from = formataddr((msg.author_id.name, msg.author_id.email))
@ -174,6 +177,9 @@ class mail_notification(osv.Model):
'email_from': email_from,
'references': references,
}
if 'mail_server_id' in context:
# temporary workaround for mail from send mail wizard
mail_values['mail_server_id'] = context['mail_server_id']
email_notif_id = mail_mail.create(cr, uid, mail_values, context=context)
try:
return mail_mail.send(cr, uid, [email_notif_id], recipient_ids=notify_partner_ids, context=context)