我想通过Odoo13中的chatter发送消息。我使用了message_post()方法,但它既不出现在chatter中,也不出现在讨论应用程序中(像用户发送的普通聊天或odoo机器人)。
奇怪的是,这条消息是在我检查它的Settings > Technical > Messages时创建的。下面是我的代码:
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“类型的模型。
你能帮我一下吗?
发布于 2020-08-24 18:16:19
终于,我可以处理它了。系统需要使用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)
https://stackoverflow.com/questions/63557264
复制相似问题