【问题标题】:Sending Email in Odoo Record does not exist在 Odoo 记录中发送电子邮件不存在
【发布时间】:2019-07-26 02:37:14
【问题描述】:

我正在尝试在订阅模块中发送电子邮件,如果订阅在 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: ('记录不存在或已被删除。', None)

【问题讨论】:

    标签: python-3.x odoo-12


    【解决方案1】:

    不要使用 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不能运行,你必须设置自己的触发按钮,

    【讨论】:

      【解决方案2】:

      这将是一种更好的方法,而不是按名称搜索模板,您可以通过 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)
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2023-01-13
        • 1970-01-01
        • 2013-04-03
        • 1970-01-01
        • 1970-01-01
        • 2020-03-26
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多