Odoo14:使用模板中的记录集通过代码发送电子邮件



使用计划任务,我需要发送一封电子邮件,通知打开任务的状态。在得到与我的搜索相对应的记录集后,我找到了如何加载模板并发送电子邮件:

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

相关内容

最新更新