【问题标题】:Odoo 13 : How to use message_post() to send message in the chatter?Odoo 13:如何使用 message_post() 在聊天中发送消息?
【发布时间】:2020-08-24 08:23:55
【问题描述】:

我想通过 odoo 13 中的 chatter 发送消息。我使用方法 message_post() 但它既没有出现在 chatter 中,也没有出现在讨论应用程序中(就像用户或 odoo bot 发送的普通聊天一样)。
奇怪的是,当我检查设置 > 技术 > 消息时会创建该消息。 这是我的代码:
                    try:
                        employee.message_post(
                        subject=(_("Timesheet reminder")),
                        body="Nous vous informons que vous n'avez pas complété votre feuille de temps du %s" % (yesterday.strftime('%d-%m-%Y')),
                        message_type='comment',
                        subtype='mail.mt_comment',
                    )
                    except Exception as e:
                        _logger.critical(e)

employee 是“hr.employee”类型的模型。
你能帮帮我吗?

【问题讨论】:

    标签: python python-3.x odoo


    【解决方案1】:

    终于,我可以应付了。系统需要使用 mail.channel 而不是 mail.message。这是代码:

    # sending message
    try:
        channel_odoo_bot_users = '%s, %s' % (odoo_bot.name, employee.user_id.name)
        channel_obj = self.env['mail.channel']
        channel_id = channel_obj.search([('name', 'like', channel_odoo_bot_users)])
        if not channel_id:
            channel_id = channel_obj.create({
                'name': channel_odoo_bot_users,
                'email_send': False,
                'channel_type': 'chat',
                'public': 'private',
                'channel_partner_ids': [(4, odoo_bot.partner_id.id), (4, employee.user_id.partner_id.id)]
            })
        channel_id.message_post(
            subject="Timesheet reminder",
            body="Nous vous informons que vous n'avez pas complété votre feuille de temps du %s" % (yesterday.strftime('%d-%m-%Y')),
            message_type='comment',
            subtype='mail.mt_comment',
           )
    except Exception as e:
        _logger.critical(e)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-04-14
      • 1970-01-01
      • 2019-08-24
      • 1970-01-01
      • 1970-01-01
      • 2017-02-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多