Files
odoo_source/addons/website_mail_channel/models/mail_mail.py
T
Thibault Delavallée 6eda1dcb7a [REF] mail: simplify email send code and remove unnecessary methods
Send methods of mail.mail model are set private and simplified. Those
methods have been written when a lot of overrides were necessary to
generate notification emails. Since then the flow has changed but
methods have not been updated completely. This commit therefore simplified
a bit the call chain and parameters.

This commit is purely technical and does not hold any functional change.
Purpose is to clean code in order to prepare future changes in mail
application.
2018-02-26 14:15:08 +01:00

36 lines
1.5 KiB
Python

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import api, models, tools, _
from odoo.addons.http_routing.models.ir_http import slug
class MailMail(models.Model):
_inherit = 'mail.mail'
@api.multi
def _send_prepare_body(self):
""" Short-circuit parent method for mail groups, replace the default
footer with one appropriate for mailing-lists."""
if self.model == 'mail.channel' and self.res_id:
# no super() call on purpose, no private links that could be quoted!
channel = self.env['mail.channel'].browse(self.res_id)
base_url = self.env['ir.config_parameter'].sudo().get_param('web.base.url')
vals = {
'maillist': _('Mailing-List'),
'post_to': _('Post to'),
'unsub': _('Unsubscribe'),
'mailto': 'mailto:%s@%s' % (channel.alias_name, channel.alias_domain),
'group_url': '%s/groups/%s' % (base_url, slug(channel)),
'unsub_url': '%s/groups?unsubscribe' % (base_url,),
}
footer = """_______________________________________________
%(maillist)s: %(group_url)s
%(post_to)s: %(mailto)s
%(unsub)s: %(unsub_url)s
""" % vals
body = tools.append_content_to_html(self.body, footer, container_tag='div')
return body
else:
return super(MailMail, self)._send_prepare_body()