From aac3be7196800e33a35d2eee92019978a37cf88c Mon Sep 17 00:00:00 2001 From: "Laurent Mignon (ACSONE)" Date: Mon, 30 May 2016 13:11:09 +0200 Subject: [PATCH] [FIX] Call to generate_email can be done with a list of ids or only one id (#65) fixes #64 --- email_template_qweb/models/mail_template.py | 6 +++++- email_template_qweb/tests/test_mail_template_qweb.py | 9 +++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/email_template_qweb/models/mail_template.py b/email_template_qweb/models/mail_template.py index 978e3bf2..a8865a70 100644 --- a/email_template_qweb/models/mail_template.py +++ b/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]] diff --git a/email_template_qweb/tests/test_mail_template_qweb.py b/email_template_qweb/tests/test_mail_template_qweb.py index c80773e8..c82864d8 100644 --- a/email_template_qweb/tests/test_mail_template_qweb.py +++ b/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 + '