Skip to Content
Меню
Вам необхідно зареєструватися, щоб взаємодіяти зі спільнотою.
Це запитання позначене
3 Відповіді
9233 Переглядів

I am trying to implement a component which displays in Systray currently running task in timer.timer model (Odoo 15 Enterprise)

I've extended the model to send a payload to trigger an action in the component


class TimerTimer(models.Model):
  _inherit = 'timer.timer'

  def create(self, vals):
    record = super(TimerTimer, self).create(vals)
    self.env['bus.bus']._sendone(record.user_id.partner_id, "timer.timer/updated", {})
    return record

  def write(self, vals):
    record = super(TimerTimer, self).write(vals)
    self.env['bus.bus']._sendone(self.user_id.partner_id, "timer.timer/updated", {})
    return record

I can see the payload incoming to browser via poll request. Now, how to subscribe to it in my component? I've tried this:


class Timer extends Component {
    setup() {
        let self = this
        console.log("EventBus")
        console.log(self\.env\.bus\)
\ \ \ \ \ \ \ \
\ \ \ \ \ \ \ \  \    \   useBus\(self.env.bus, "timer.timer/updated", event => {
            console.log(event)
        })
}
Timer.template = "eaxpl_timesheet_timer.Timer"
registry.category("systray").add("eaxpl_timesheet_timer.Timer", { Component: Timer }, { sequence: 3 });

export default Timer

Unfortunately it does not seem to work. The event bus object is there but it does not seem to catch the payload incoming. I have tried listening on:

  • timer.timer/updated
  • notification

Any hints appreciated


Аватар
Відмінити
Найкраща відповідь

Finally i got it, after 3 days of work and research..


In front end for example for create a new custom channel
/** @odoo-module **/
// BusListener.js
import { registry } from"@web/core/registry";
constmyService= {    dependencies: ['bus_service'],    start(_, { bus_service }) {        console.log('Add notification')
        bus_service.addChannel('my-event') // New channel
        bus_service.addEventListener('notification', ({ detail: notifications }) => {            console.log({ notifications })            for (const { payload, type } ofnotifications) {                if (type==="my-event") {                    this.myEventHandler(payload)                }            }        });
        bus_service.addEventListener('connect', () => {            console.log('Connected')        });
        bus_service.start();
    },
    myEventHandler(event) {        console.log({ event });    }};
registry.category("services").add("myService", myService);
In backend:

# -*- coding: utf-8 -*-fromodooimportmodels, fields, api
classBusModel(models.Model):    _name='bus_test'    _description="Bus para my modulo"
    name=fields.Char(string="Name")
    @api.model    defmy_method(self):        self.env['bus.bus']._sendone('my-event', 'my-event', {            'server_version': "my-event"        })
Аватар
Відмінити

Odoo forum for developers the forum can't paste a code of developers, it is a shit of post system

Найкраща відповідь

setup() {

this.env.bus.on('WEB_CLIENT_READY', null, async () => {

const bus_service = owl.Component.env.services.bus_service;

bus_service.onNotification(this, this._onNotification);

bus_service.addChannel(/* record.user_id.partner_id */);

bus_service.startPolling();

});

}

Sorry for formatting, this web editor is terrible. Grep 15.0 for plenty of examples of what _onNotification looks like.

Аватар
Відмінити
Найкраща відповідь

did you ever find an answer?

Аватар
Відмінити
Related Posts Відповіді Переглядів Дія
4
квіт. 25
3946
0
черв. 24
1088
1
груд. 23
2308
0
черв. 24
1411
2
трав. 24
1349