Fire an event globally on load of every view in odoo

23 views Asked by At

A global solution to fire an event on load of every view in odoo admin side

In odoo16 I am trying to inherit view from view.js as

/** @odoo-module */

console.log('Hoping view be inherited');
import { registry } from "@web/core/registry";
import {View } from '@web/views/view';

class MyView extends View{
    setup() {
        super.setup();
        console.log('View is inherited successfully')
    }
}

This console is shown console.log('Hoping view be inherited'); means file runs successfully as its included in assets->web.assets_backend->[] in my custom module manifest

but following is never reached console.log('View is inherited successfully')

Note: the setup of original web/stativ/src/views/view.js

export class View extends Component {
    setup() {
       ...
       console.log('Appears  every time a view is loaded')
    }
}

is called every time a view is loaded

I have also tried to use hooks like

/** @odoo-module */

import { registry } from "@web/core/registry";

const myViewHook = () => {
    // Your custom logic to modify views here
    console.log('Executing on every view load');
};

registry.add("web.dom_loaded", myViewHook);

but it also does not work

0

There are 0 answers