Skip to Content
Menu
This question has been flagged
5297 Views
Hi guys,

I'm using Odoo 9.0 and would like to notify the web client of changes to the currently logged in user's record.

According to this article: \http://odoo-development.readthedocs.io/en/latest/odoo/models/bus.bus.html, there are two ways to add a new bus channel.

1) By extending the BusController in the bus module

import openerp.addons.bus.controllers.main.BusController

class MyController(BusController):
    def _poll(self, dbname, channels, last, options):
        if request.session.uid:
            channels = list(channels)
            channels.append((request.db, 'my.channel', request.env.uid))
        return super(MyController, self)._poll(dbname, channels, last, options)

I've tried this, and it indeed works. You can also see it working in the mail module. BUT, the way our server is setup is our addons path is *before* Odoo's addons path, like so:

addons_path = /my/company/addons,/opt/odoo/addons

This means that by the time I start my Odoo server and my module gets loaded, the bus module hasn't been loaded yet and I get an import error "BusController" doesn't exist. If I swap the addon path around, it works. Unfortunately this is not a fix for me.

2) The second way of adding a bus channel is through JS

var session = require('web.session');
var bus = require('bus.bus').bus;

bus.add_channel(JSON.stringify([session.db, 'my.channel', session.uid]));

I've tried to find example usage of this, but can't find any. This doesn't seem to be working because if I post to the channel there is no notification on the bus.

Any help on solving either method 1) or 2) would be appreciated.

PS: My module does depend on "bus" in "__openerp__.py"
PPS: I've also tried inserting the bus module in the "--load" parameter when running Odoo
Avatar
Discard

Could you clarify what kind of channel you need to create and what it will be the usage of that new channel type? because maybe you doesn't need to do nothing too tricky

Related Posts Replies Views Activity
0
Jun 24
473
1
Jun 23
798
1
May 23
608
1
Oct 22
2692
0
May 20
2322