python-3.x - odoo 从代码向用户发送消息(通知)

我正在尝试制作一个模块来检查 Skype 并通知用户有关新消息的信息。我遇到了在 odoo 中通过他的 id 向用户发送消息的问题,我是否需要从消息模块的某个地方继承,或者我是否需要以某种方式管理代码以便发送消息。

初始化.py

from . import controllers
from . import models
import threading
import skpy



class MySkype(skpy.SkypeEventLoop):
    def onEvent(self, event):
        if isinstance(event, skpy.SkypeNewMessageEvent):
            print(repr(event))
            message = ('New message from user {} at {}: \'{} \''.format(event.msg.userId,
                                                                        event.msg.time.strftime(
                                                                            '%H:%M dd. %d.%m.%Y'),
                                                                        event.msg.content))
            models.models.skype_bot.SentMail(message)

if __name__ == '__main__':
    from skpy import Skype
    global client
    global sk
    client = Skype('', '', '.skype_token')
    sk = MySkype(tokenFile=".skype_token", autoAck=True)
    thread = threading.Thread(target=sk.loop)
    thread.start()

模型.py

    from odoo import models, fields, api
import threading
import skpy
import logging

_logger = logging.getLogger(__name__)

class skype_bot(models.Model):
    _inherit = 'skype_bot'
    _name = 'my.skype'
    _description = 'My Skype'



    def SentMail(self, message):
        self.env['mail.message'].create({'message_type': "notification",
                                         "subtype": self.env.ref("mail.mt_comment").id,  # subject type
                                         'body': message,
                                         'subject': "Message subject",
                                         'needaction_partner_ids': [(4, 3, 1)],
                                         # partner to whom you send notification
                                         })


        self.message_post(
            subject='Skype message',
            body=message,
            partner_ids=[(4, 3, 1)]
        )

    SentMail("test")

你可以在这里看到所有的代码https://github.com/Sabrjkee/odootry

最佳答案

需要在模型中使用_inherit = ['mail.thread']

https://stackoverflow.com/questions/54252865/

相关文章:

hibernate - 关于 EntityManagerFactory 和 SessionFacto

c++ - 如何在嵌入式 V8 中重置全局对象?

bash - 如何以编程方式从 docker-compose.yml 中删除服务?

d3.js - 如何将 csv 文件加载到 nuxt vue 组件中

javascript - 为 monaco-editor 添加 vue js 语言支持

c# - 偷看后从并发队列中删除元素的模式

r - 如何从 Shiny 中的 plotly 事件中获取方面数据

angular - 如何使 angular cli 允许我使用名称的内容哈希加载图标

nlp - 如何使用 torchtext 添加功能?

swift - 如何修复此 'required condition is false: format