Odoo14:使用模板中的记录集通过代码发送电子邮件
Odoo14: Send an email through code using a recordset in the template
使用计划任务,我需要发送一封电子邮件,通知未完成任务的状态。得到对应搜索的记录集后,我找到了加载模板和发送邮件的方法:
mail_template = self.env.ref('test_email.email_template')
mail_template.send_mail(self.id)
但我只能访问 $object 中的当前记录。我希望能够将记录集传递给模板并对其进行循环。
您可以使用上下文将数据“传输”到邮件呈现中:
mail_template.with_context(my_recordset=my_recordset).send_mail(self.id)
在您的邮件模板中只需使用 ctx
:
%for record in ctx.get('my_recordset', []):
<div>${record.my_attribute}</div>
%endfor
使用计划任务,我需要发送一封电子邮件,通知未完成任务的状态。得到对应搜索的记录集后,我找到了加载模板和发送邮件的方法:
mail_template = self.env.ref('test_email.email_template')
mail_template.send_mail(self.id)
但我只能访问 $object 中的当前记录。我希望能够将记录集传递给模板并对其进行循环。
您可以使用上下文将数据“传输”到邮件呈现中:
mail_template.with_context(my_recordset=my_recordset).send_mail(self.id)
在您的邮件模板中只需使用 ctx
:
%for record in ctx.get('my_recordset', []):
<div>${record.my_attribute}</div>
%endfor