Search code examples
javascriptodooodoo-12

How to override action_registry js in odoo [12.0]


I have the following js file that handles a widget and I would like to overwrite and add code for custom events function, but when I tried to instantiate, nothing seems to be on the object:

This a reference for the script that I want to overwrite

odoo.define('my_module.my_report', function (require) {
'use strict';
var myWidget = AbstractAction.extend(ControlPanelMixin, {
        custom_events: {
             },
        }
        core.action_registry.add('my_report', myWidget );

        return myWidget 
   });
});

I have tried inheriting using the following:

var InheritedWidget = require('my_module.my_report); 

and also:

var InheritedWidget = core.action_registry.get('my_report');

and when I tried to override, nothing seems to happen:

InheritedWidget.include({
    custom_events: {
     //My custom code goes here
       }
})

Do you know how to override this widget or method?


Solution

  • You need to extend the custom_events of an existing widget.

    var InheritedWidget = require('my_module.my_report'); 
    
    InheritedWidget.include({
        custom_events: _.extend({}, InheritedWidget.prototype.custom_events, {
            //My custom code goes here
        }),
    });
    

    For more details refer to the event system documentation.