Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

1

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

By
Henrik Norlin
on 8/12/15, 4:16 PM 2,438 views

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?

3

Axel Mendoza

--Axel Mendoza--
10238
| 7 7 8
Camaguey, Cuba
--Axel Mendoza--

DevOps - Full stack - Software Architect - Developer - Technology Integrator

I could help you to develop anything and solve complex problems based on technologies, integrations and tricky stuffs mostly in Python with OpenERP/Odoo, Zato, Django and many others frameworks programming languages and technologies.

I offers consulting services to anyone with an unanswered questions or needs for customizations. Think about it, maybe it's better to have an expert to solve your issues and projects than having a full time employee trying to understand what to do an how

Reach me at aekroft@gmail.com

Axel Mendoza
On 8/12/15, 10:39 PM

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

0
Henrik Norlin
On 8/13/15, 2:19 AM

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

}

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

4 follower(s)

Stats

Asked: 8/12/15, 4:16 PM
Seen: 2438 times
Last updated: 10/8/16, 4:53 AM