@ api.onchange不会触发odoo12

时间:2019-02-04 14:10:16

标签: python multithreading odoo odoo-12

我正在尝试使用@ api.onchange('skype_message'),但是当skype_message字段更改时,什么也没发生(我的消息发送功能未调用)

我的模特:

import logging
from odoo import models, fields, api

_logger = logging.getLogger(__name__)



class SkypeBot(models.Model):
    _name = 'my.skype'
    _inherit = ['mail.thread', 'mail.activity']
    _description = 'My Skype'

    skype_login = fields.Char('Your skype Login')
    skype_password = fields.Char('Your skype password')
    skype_message = fields.Char()

    @api.onchange('skype_message')
    def send_message(self):
        _logger.info('%%%%%%%'*5)
        _logger.warning('send_message CALLED')
        _logger.info('%%%%%%%'*5)
        partner_id = self.env['res.users'].search([('id', '=', 2)]).partner_id.id
        _logger.info('???????????' * 10)
        _logger.warning(partner_id)
        _logger.info('???????????' * 10)
        self.message_post({'message_type': 'notification',
                                         'subtype': self.env.ref('mail.mt_comment').id,  # subject type
                                         'body': SkypeBot.skype_message,
                                         'subject': 'Message subject',
                                         'partner_ids': [(4, partner_id), ],
                                         # partner to whom you send notification
                                         })

        _logger.info('???????????' * 10)
        _logger.warning('MESSAGE SENT')

我从另一个代码在其中的线程中更改了一个变量

import skpy
import logging
import threading
from . import skype_model


_logger = logging.getLogger(__name__)

class MySkype(skpy.SkypeEventLoop):
    def onEvent(self, event):
        if isinstance(event, skpy.SkypeNewMessageEvent):

            skype_model.SkypeBot.skype_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.warning(event)
            _logger.info('--------' * 5)
            _logger.warning(skype_model.SkypeBot.skype_message)
            _logger.info('--------' * 5)





from skpy import Skype

global client
global sk
sk = MySkype('1', '11', autoAck=True)
thread = threading.Thread(target=sk.loop)
thread.start()

我的 init .py:

import logging

_logger = logging.getLogger(__name__)


from . import controllers

_logger.info('................' * 10)
_logger.warning("Start Import skype_model")
from . import skype_model
_logger.warning("Model has been import")
_logger.info('................' * 10)

_logger.info('!!!!!!!!!!!!!!!!!!!' * 10)
_logger.warning("Change field")
skype_model.SkypeBot.skype_message = "Test!"
_logger.warning("Changed")
_logger.info('^^^^^^^^'*10)
_logger.warning(skype_model.SkypeBot.skype_message)
_logger.info('!!!!!!!!!!!!!!!!!!!' * 10)

_logger.info('................' * 10)
_logger.warning("Start Import Send_message")
from . import skype_send_message
_logger.warning("Send_message has been import")
_logger.info('................' * 10)


_logger.info('!!!!!!!!!!!!!!!!!!!' * 10)
_logger.warning(skype_model.SkypeBot.skype_message)
_logger.info('!!!!!!!!!!!!!!!!!!!' * 10)

在控制台中,我看到我成功更改了变量,但是此后没有任何反应 控制台:

лют 04 16:55:28 PK odoo12[17510]: 2019-02-04 13:55:28,412 17510 INFO ? odoo.http: HTTP Configuring static files
лют 04 16:55:28 PK odoo12[17510]: 2019-02-04 13:55:28,422 17510 INFO odoo12 odoo.modules.loading: loading 1 modules...
лют 04 16:55:28 PK odoo12[17510]: 2019-02-04 13:55:28,433 17510 INFO odoo12 odoo.modules.loading: 1 modules loaded in 0.01s, 0 queries
лют 04 16:55:28 PK odoo12[17510]: 2019-02-04 13:55:28,442 17510 INFO odoo12 odoo.modules.loading: loading 20 modules...
лют 04 16:55:28 PK odoo12[17510]: 2019-02-04 13:55:28,578 17510 INFO odoo12 odoo.addons.skype_bot: ............................................................................................................
лют 04 16:55:28 PK odoo12[17510]: 2019-02-04 13:55:28,578 17510 WARNING odoo12 odoo.addons.skype_bot: Start Import skype_model
лют 04 16:55:28 PK odoo12[17510]: 2019-02-04 13:55:28,579 17510 WARNING odoo12 odoo.addons.skype_bot: Model has been import
лют 04 16:55:28 PK odoo12[17510]: 2019-02-04 13:55:28,579 17510 INFO odoo12 odoo.addons.skype_bot: ............................................................................................................
лют 04 16:55:28 PK odoo12[17510]: 2019-02-04 13:55:28,580 17510 INFO odoo12 odoo.addons.skype_bot: !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
лют 04 16:55:28 PK odoo12[17510]: 2019-02-04 13:55:28,580 17510 WARNING odoo12 odoo.addons.skype_bot: Change field
лют 04 16:55:28 PK odoo12[17510]: 2019-02-04 13:55:28,580 17510 WARNING odoo12 odoo.addons.skype_bot: Changed
лют 04 16:55:28 PK odoo12[17510]: 2019-02-04 13:55:28,580 17510 INFO odoo12 odoo.addons.skype_bot: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
лют 04 16:55:28 PK odoo12[17510]: 2019-02-04 13:55:28,581 17510 WARNING odoo12 odoo.addons.skype_bot: Test!
лют 04 16:55:28 PK odoo12[17510]: 2019-02-04 13:55:28,581 17510 INFO odoo12 odoo.addons.skype_bot: !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
лют 04 16:55:28 PK odoo12[17510]: 2019-02-04 13:55:28,581 17510 INFO odoo12 odoo.addons.skype_bot: ............................................................................................................
лют 04 16:55:28 PK odoo12[17510]: 2019-02-04 13:55:28,581 17510 WARNING odoo12 odoo.addons.skype_bot: Start Import Send_message
лют 04 16:55:32 PK odoo12[17510]: 2019-02-04 13:55:32,154 17510 WARNING odoo12 odoo.addons.skype_bot: Send_message has been import
лют 04 16:55:32 PK odoo12[17510]: 2019-02-04 13:55:32,155 17510 INFO odoo12 odoo.addons.skype_bot: ............................................................................................................
лют 04 16:55:32 PK odoo12[17510]: 2019-02-04 13:55:32,155 17510 INFO odoo12 odoo.addons.skype_bot: !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
лют 04 16:55:32 PK odoo12[17510]: 2019-02-04 13:55:32,155 17510 WARNING odoo12 odoo.addons.skype_bot: Test!
лют 04 16:55:32 PK odoo12[17510]: 2019-02-04 13:55:32,155 17510 INFO odoo12 odoo.addons.skype_bot: !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
лют 04 16:55:32 PK odoo12[17510]: 2019-02-04 13:55:32,168 17510 INFO odoo12 odoo.addons.sms.wizard.send_sms: The `phonenumbers` Python module is not available. Phone number validation will be skipped. Try `p
лют 04 16:55:32 PK odoo12[17510]: 2019-02-04 13:55:32,188 17510 INFO odoo12 odoo.modules.loading: 20 modules loaded in 3.75s, 0 queries
лют 04 16:55:32 PK odoo12[17510]: 2019-02-04 13:55:32,403 17510 INFO odoo12 odoo.modules.loading: Modules loaded.
лют 04 16:55:32 PK odoo12[17510]: 2019-02-04 13:55:32,406 17510 INFO odoo12 odoo.addons.base.models.ir_http: Generating routing map
лют 04 16:55:32 PK odoo12[17510]: 2019-02-04 13:55:32,505 17510 INFO ? odoo.addons.bus.models.bus: Bus.loop listen imbus on db postgres
лют 04 16:55:52 PK odoo12[17510]: 2019-02-04 13:55:52,166 17510 INFO ?

odoo.addons.skype_bot.skype_send_message: —--------------------------------------
лют 04 16:55:52 PK odoo12[17510]: 2019-02-04 13:55:52,167 17510 WARNING ? odoo.addons.skype_bot.skype_send_message: [SkypeNewMessageEvent]
лют 04 16:55:52 PK odoo12[17510]: Id: 1014
лют 04 16:55:52 PK odoo12[17510]: Type: NewMessage
лют 04 16:55:52 PK odoo12[17510]: Time: 2019-02-04 13:55:52
лют 04 16:55:52 PK odoo12[17510]: MsgId: 1549288551954
лют 04 16:55:52 PK odoo12[17510]: 2019-02-04 13:55:52,168 17510 INFO ? odoo.addons.skype_bot.skype_send_message: —--------------------------------------
лют 04 16:55:52 PK odoo12[17510]: 2019-02-04 13:55:52,168 17510 WARNING ? odoo.addons.skype_bot.skype_send_message: New message from user andreykychyc at 13:55 dd. 04.02.2019: '11132 '
лют 04 16:55:52 PK odoo12[17510]: 2019-02-04 13:55:52,168 17510 INFO ? odoo.addons.skype_bot.skype_send_message: —--------------------------------------
лют 04 16:56:22 PK odoo12[17510]: 2019-02-04 13:56:22,509 17510 INFO odoo12 werkzeug: 127.0.0.1 - - [04/Feb/2019 13:56:22] "POST /longpolling/poll HTTP/1.1" 200 - 35 0.023 54.072
лют 04 16:57:12 PK odoo12[17510]: 2019-02-04 13:57:12,553 17510 INFO odoo12 werkzeug: 127.0.0.1 - - [04/Feb/2019 13:57:12] "POST /longpolling/poll HTTP/1.1" 200 - 8 0.004 50.008

可能是什么问题?该怎么解决?

0 个答案:

没有答案