[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) 2016-05-30 13:11:09 +02:00 committed by ernesto
parent ec7939b2d9
commit f12d8f5275
2 changed files with 14 additions and 1 deletions

View File

@ -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]]

View File

@ -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']
)
)