【问题标题】:How to set 'email' in author_id inherit mail.thread on Odoo如何在 author_id 中设置“电子邮件”继承 Odoo 上的 mail.thread
【发布时间】:2019-01-30 16:14:19
【问题描述】:

我继承了 Odoo12 上的mail.thread

_inherit = ['mail.thread', 'mail.activity.mixin']

并发布消息:

msg = 'message test.'
self.message_post(body=msg, email_from='Otro <otro@otro.com>', subtype='mail.mt_comment',)

image

这些消息是使用管理员用户添加的。如何将发送消息的外部用户的邮件放在字段author_id

【问题讨论】:

  • 能否提供周边代码?您可以在任何地方使用sudo(),这会将环境用户更改为管理员。而且您没有为message_post() 提供author_id,这将使Odoo 将环境用户作为作者。
  • @CZoellner 这就是问题所在,如何设置 author_id = 'other@otro.com' ...我的理解是 author_id 需要一个 id 但此消息的作者不在 odoo 数据库中.
  • 试用self.message_post(body=msg, email_from='Otro &lt;otro@otro.com&gt;', subtype='mail.mt_comment', author_id=False)
  • @CZoellner ...哦,谢谢!有效

标签: python odoo message


【解决方案1】:

试试self.message_post(body=msg, email_from='Otro &lt;otro@otro.com&gt;', subtype='mail.mt_comment', author_id=False)

author_id=False 将告诉 Odoo 使用 email_from 作为作者。

我在这里找到了“窍门”:

    author_id = kwargs.get('author_id')
    if author_id is None:  # keep False values
        author_id = self.env['mail.message']._get_default_author().id

半有价值的评论# keep False values解决了大秘密;-)

None 将使用当前环境的用户。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多