Trợ giúp


How can I extend a view type? (e.g. instance.web.ListView.extend)

Henrik Norlin

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: 

The documentation says nothing about this:

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?

Ảnh đại diện
Huỷ bỏ
2 Câu trả lời
Axel Mendoza
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.form.widgets.add('char','instance.web.form.FieldChar');'char','');'char', '');
instance.web.form.custom_widgets.add('your','your class widget');

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

Ảnh đại diện
Huỷ bỏ
Henrik Norlin
Best Answer

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

I just found the documentation's link to

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');


Ảnh đại diện
Huỷ bỏ