我正在尝试制作一个模块,该模块将检查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()
models.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")
看到所有代码
答案 0 :(得分:0)
需要在模型中使用_inherit = ['mail.thread']