Browse Source

[FIX] Call to generate_email can be done with a list of ids or only one id (#65)

fixes #64
pull/341/head
Laurent Mignon (ACSONE) 8 years ago
committed by ernesto
parent
commit
f12d8f5275
  1. 6
      email_template_qweb/models/mail_template.py
  2. 9
      email_template_qweb/tests/test_mail_template_qweb.py

6
email_template_qweb/models/mail_template.py

@ -16,6 +16,10 @@ class MailTemplate(models.Model):
@api.multi
def generate_email(self, res_ids, fields=None):
multi_mode = True
if isinstance(res_ids, (int, long)):
res_ids = [res_ids]
multi_mode = False
result = super(MailTemplate, self).generate_email(
res_ids, fields=fields
)
@ -32,4 +36,4 @@ class MailTemplate(models.Model):
result[record_id]['body'] = tools.html_sanitize(
result[record_id]['body_html']
)
return result
return multi_mode and result or result[res_ids[0]]

9
email_template_qweb/tests/test_mail_template_qweb.py

@ -15,3 +15,12 @@ class TestMailTemplateQweb(TransactionCase):
mail_values[self.env.user.id]['body_html']
)
)
# the same method is also called in a non multi mode
mail_values = template.generate_email(self.env.user.id)
self.assertTrue(
# this comes from the called template if everything worked
'<footer>' in mail_values['body_html'],
'Did not rcv rendered template in response. Got: \n%s\n' % (
mail_values['body_html']
)
)
Loading…
Cancel
Save