Skip to content
Snippets Groups Projects
Commit 6a0850b5 authored by Nasreddin Boulif (bon)'s avatar Nasreddin Boulif (bon)
Browse files

[FIX] mass_mailing: replace dynamic placeholder in 'View Online' page

Steps to reproduce:

- Install `mass_mailing` module
- Create a new mailing
- Set a subject and a mailing list
- Select for the mail body the template "Thank you for joining us!'
- Add a dynamic placeholder (e.g. ${object.email})
- Click on "Send"
- Open the email received and click on "View Online"

Issue:

  The dynamic placeholder is not replaced.

Cause:

  The controller does not re-render the body based on the res_id.

Solution:

  Use `mailing` variable (that inherit from `mail.render.mixin`) to
  re-render the body based on the res_id if available (same as when
  sending the mail).
  https://github.com/odoo/odoo/blob/d3a6a20788c78ddaaff0919ea627e7b10c7ab81c/addons/mail/wizard/mail_compose_message.py#L476



opw-3133975

closes odoo/odoo#112054

Signed-off-by: default avatarNasreddin Boulif (bon) <bon@odoo.com>
parent c1d7eab2
No related branches found
No related tags found
No related merge requests found
......@@ -128,6 +128,9 @@ class MassMailController(http.Controller):
'class="o_snippet_view_in_browser" style="display: none;"'
)
if res_id:
res[mailing_id] = mailing._render_template(res[mailing_id], mailing.mailing_model_real, [res_id], post_process=True)[res_id]
return request.render('mass_mailing.view', {
'body': res[mailing_id],
})
......
......@@ -20,3 +20,22 @@ class TestMassMailingControllers(MassMailCommon, HttpCase):
response = self.url_open(url)
self.assertEqual(response.status_code, 400)
def test_mailing_view(self):
mailing = self.env['mailing.mailing'].create({
'name': 'TestMailing',
'subject': 'Test',
'mailing_type': 'mail',
'body_html': '<p>Hello ${object.name} ${object.hello}</p>',
'mailing_model_id': self.env['ir.model']._get('res.partner').id,
})
partner_id = self.user_admin.partner_id
self.authenticate('admin', 'admin')
url = werkzeug.urls.url_join(mailing.get_base_url(), '/mailing/%s/view?res_id=%s' % (mailing.id, partner_id.id))
response = self.url_open(url)
self.assertEqual(response.status_code, 200)
self.assertNotIn('${', response.text)
self.assertIn("<p>Hello %s </p>" % partner_id.name, response.text)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment