在 Odoo 记录中发送电子邮件不存在

Sending Email in Odoo Record does not exist

我正在尝试在订阅模块中发送电子邮件,如果订阅在 3 天内过期,客户将收到关于他的订阅的通知

我试过在 odoo 论坛中关注,但没有人成功

@api.multi
def subs_notify(self):
    mail_template = self.env['mail.template'].search([('id', '=', 67)])
    mail_template.write({'email_to': self.partner_id.email})
    if mail_template:
        mail_template.send_mail(self.partner_id.id, force_send=True, raise_exception=True)

odoo.exceptions.MissingError: ('Record does not exist or has been deleted.', None)

不要使用 ID 搜索您的电子邮件模板,按名称或其他任何方式搜索 此代码将起作用

@api.multi
def subs_notify(self):
        mail_template = self.env['mail.template'].search([('name', 'like', 'Confirm Your Email')])
        if mail_template:
            mail_template.write({
                'email_to': self.partner_id.email,
                })
            self.env['mail.template'].browse(mail_template.id).send_mail(self.id,force_send=True)

如果api.multi不会运行,您必须设置自己的触发按钮,

这将是一个更好的方法,而不是通过名称搜索模板,您可以通过 self.env.ref 获取模板 ID

    template_id = self.env.ref('your_module_name.your_mail_template_id')
    if template_id:
        template_id.write({'email_to': self.partner_id.email})
        template_id.send_mail(self.id,force_send=True)