This question has been flagged

In accounting, journal items list view has a special filter for period and journal. The action view_mode = tree_account_move_line_quickadd which links to a javascript file where I find instance.web.ListView.extend({ ... }). I am not able to reproduce this in another model.

Source code: https://github.com/odoo/odoo/search?q=tree_account_move_line_quickadd 

The documentation says nothing about this: https://www.odoo.com/documentation/8.0/howtos/web.html

The documentation module oepetstore works well with: local.Homepage = instance.Widget.extend({ ... })

But this fails: local.Test = local.Homepage.extend({ ... })

How do I extend a custom javascript jQuery class?

Avatar
Discard
Best Answer

There are two ways, extend and include:

- with extends you create a new widget that needs to be registered in Odoo to be used

- with include you modify in place an existing Odoo widget and no need to be registered in Odoo to be used since the modified widget is already registered.

Where you can register you widget extensions, that depends on the type of widget that you use as base of your widget and also depends on the use that you will do of the widget. You could register your widget as:

- form field

- form tag

- form custom

- search field

- custom_filter

- client_action type

- view type

- list column field

as long as I know.

How you could register your widgets for every case? By example:

instance.web.views.add('form', 'instance.web.FormView');
instance.web.client_actions.add('easyrtc','instance.easyrtc.widget');
instance.web.form.widgets.add('char','instance.web.form.FieldChar');
instance.web.search.fields.add('char','instance.web.search.CharField');
instance.web.search.custom_filters.add('char', 'instance.web.search.ExtendedSearchProposition.Char');
instance.web.form.tags.add('button','instance.web.form.WidgetButton');
instance.web.form.custom_widgets.add('your','your class widget');
instance.web.list.columns.add('field','instance.web.list.Column');

You always will be registering your widget in an instance.web.Registry that Odoo will be using for pick your new widgets. The way that you instruct Odoo to pick your new widget varying for every type of widget and the type of Registry that you use.

Hope this helps

Avatar
Discard
Author Best Answer

Thanks Axel for explaining extend vs include, and the Registry add examples.

I just found the documentation's link to http://ejohn.org/blog/simple-javascript-inheritance/

Hopefully this will help me to understand how inheritance works.

Update: Here is a basic list extension that works (set the action view_mode to tree_oepetstore_message_of_the_day_message,form):

openerp.oepetstore = function(instance, local) {

var _t = instance.web._t,

_lt = instance.web._lt;

var QWeb = instance.web.qweb;

instance.web.oepetstore = instance.web.oepetstore || {};

instance.web.oepetstore.MessageListView = instance.web.ListView.extend({

init: function() {

this._super.apply(this, arguments);

},

start:function() {

var tmp = this._super.apply(this, arguments);

var self = this;

var defs = [];

return $.when(tmp, defs);

},

});

instance.web.views.add('tree_oepetstore_message_of_the_day_message', 'instance.web.oepetstore.MessageListView');

}

Avatar
Discard