You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Odoo 16调用MailThread._message_auto_subscribe_notify()缺失template参数问题

解决Odoo 16中_message_auto_subscribe_notify方法的参数缺失问题

参数说明

Odoo 16 重构了_message_auto_subscribe_notify方法,要求必须传入第二个参数template,它可以是:

  • 邮件模板的XML ID字符串(推荐,便于模块部署)
  • mail.template模型的记录集对象

这个参数指定发送订阅通知时使用的邮件模板,方法会基于模板生成邮件内容并发送给新订阅的联系人。

自定义邮件模板示例

在模块的data目录下创建mail_templates.xml,定义一个订阅通知模板:

<odoo>
    <record id="template_subscription_notify" model="mail.template">
        <field name="name">订阅通知模板</field>
        <field name="model_id" ref="base.model_res_partner"/>
        <field name="subject">您已订阅${object.name}的更新</field>
        <field name="body_html" type="html">
            <p>您好,</p>
            <p>您已成功订阅${object.name}的动态更新,后续相关通知将发送至您的邮箱。</p>
            <p>如有疑问,请联系管理员。</p>
        </field>
        <field name="email_from">${(user.email or '')}</field>
        <field name="auto_delete" eval="True"/>
    </record>
</odoo>

注意:替换model_id的ref值为你实际业务对应的模型XML ID,比如你的自定义模型my_module.model_my_record。

修正后的调用代码

方式1:传入模板XML ID(推荐)

if approver.user_id:
    # 替换为你定义的模板XML ID
    self._message_auto_subscribe_notify(
        [approver.user_id.partner_id.id],
        template="my_module.template_subscription_notify"
    )

方式2:传入模板记录集

if approver.user_id:
    template = self.env.ref("my_module.template_subscription_notify")
    self._message_auto_subscribe_notify(
        [approver.user_id.partner_id.id],
        template=template
    )

内容的提问来源于stack exchange,提问作者Bappi Saha

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.01 16:00:59