Skip to Content
Menu
This question has been flagged
8 Replies
12105 Views

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()
Avatar
Discard
Author

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'

Author

try to use recs as shown here https://www.linkedin.com/in/andrei-kuchuk-526412140/ it says me that model ha no method browes

Author

one person has told me that i need to initialize ODOO Environment, but i don't understand how to do it

Best Answer

Hi, 

I assume that skype_bot is an instance of my.skype object.
You only need to do this : skype_bot.send_message(message)

You can write back if this does not help.

Avatar
Discard
Author Best Answer
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'
Avatar
Discard

Well then, i don't think skype_bot in an instance of the object my.skype

Can you print it and tell me the output ?

Author

could you tell me more precisely what i need to print

print(skype_bot)

Author

I print this code

_logger.info('================' * 10)

_logger.warning(print(skype_bot))

print(skype_bot)

_logger.warning(skype_bot)

_logger.info('================' * 10)

and get this

сту 25 14:40:54 PK odoo12[16879]: 2019-01-25 11:40:54,410 16879 INFO odoo12 odoo.addons.skype_bot.models.models: ==============================================

сту 25 14:40:54 PK odoo12[16879]: 2019-01-25 11:40:54,410 16879 WARNING odoo12 odoo.addons.skype_bot.models.models: None

сту 25 14:40:54 PK odoo12[16879]: 2019-01-25 11:40:54,410 16879 WARNING odoo12 odoo.addons.skype_bot.models.models: <class 'odoo.addons.skype_bot.models.models.skype_bot'>

сту 25 14:40:54 PK odoo12[16879]: 2019-01-25 11:40:54,411 16879 INFO odoo12 odoo.addons.skype_bot.models.models: =========================================================

Author

i try to call func like: with api.Environment.manage(): , it's didn't help me too

Best Answer

Hi,

Call method with self.send_message(message)

Avatar
Discard
Related Posts Replies Views Activity
1
Jun 19
8089
2
Dec 23
11993
0
Oct 23
33
3
Oct 23
787
1
Oct 23
569