how to use the environment correctly, so that I can call the method sent_message and pass self as a recordset and the string "message". To avoid errors of lack of arguments
models.py
from odoo import models, fields, api
import logging
import skpy
import threading
_logger = logging.getLogger(__name__)
class skype_bot(models.AbstractModel):
_name ='my.skype'
_inherit =['mail.thread',]
_description ='My Skype'
@api.multi def send_message(self, message):
_loger.info('==='*5)
partner_id = self.env['res.users'].search([('id','=',2)]).partner_id.id self.env['mail.message'].create({'message_type':'notification','subtype': self.env.ref('mail.mt_comment').id,# subject type'body': message,'subject':'Message subject','partner_ids':[(4, partner_id),],# partner to whom you send notification})classMySkype(skpy.SkypeEventLoop):
def onEvent(self, event):
if isinstance(event, skpy.SkypeNewMessageEvent):
message =('New message from user {} at {}: \'{} \''.format(event.msg.userId,
event.msg.time.strftime('%H:%M dd. %d.%m.%Y'),
event.msg.content))
_logger.info('----'*5)
_logger.info(message)
_logger.info('----'*5)
skype_bot.send_message(message=message)
class MySkype(skpy.SkypeEventLoop) i start in thread from init.py, and when an event occurs, it should call skype_bot.send_message, but when it calling this fuc become an error missing 1 argument 'self'
init.py
sk = models.models.MySkype(user='', pwd='', autoAck=True)
thread = threading.Thread(target=sk.loop)
thread.start()
if i use skype_bot.send_message(message) i get this
сту 25 13:23:55 PK odoo12[15652]: File "/opt/odoo12/odoo-custom-addons/skype_bot/models/models.py", line 42, in <module>
сту 25 13:23:55 PK odoo12[15652]: class MySkype(skpy.SkypeEventLoop):
сту 25 13:23:55 PK odoo12[15652]: File "/opt/odoo12/odoo-custom-addons/skype_bot/models/models.py", line 86, in MySkype
сту 25 13:23:55 PK odoo12[15652]: skype_bot.send_message(message)
сту 25 13:23:55 PK odoo12[15652]: TypeError: send_message() missing 1 required positional argument: 'message'
try to use recs as shown here https://www.linkedin.com/in/andrei-kuchuk-526412140/ it says me that model ha no method browes
sry wrong link https://www.odoo.com/documentation/12.0/reference/orm.html#environment
one person has told me that i need to initialize ODOO Environment, but i don't understand how to do it