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.

0

Override Many2ManyListView under web.form_relational !!

By
Pawan
on 7/8/16, 3:19 AM 301 views

Hello guys,

I have a requirement in which i have to override Many2ManyListView class from "web/static/src/js/views/form_relational_widget.js" under "web.form_relational"

But as web.form_relational does not return 'Many2ManyListView'(so i can't use '.' notation to access) nor its adding it in form_registery(to access it from registery), i am not getting the correct  way to override 'Many2ManyListView'


Any help would be appreciated...


Thanks!

1

Axel Mendoza

--Axel Mendoza--
10205
| 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 7/8/16, 7:08 PM

*** update that works directly without more investigation, i will left the original answer as a reference ***

Odoo class/widget functions extend and include have something in common. That is that both functions apply the received javascript object properties to the class/widget. The difference between those Odoo class/widget functions is that the extend function is used to get a copy of the Odoo class/widget with the modifications without been modify the original class/widget by returning the modifications in a new class/widget. The include function will do the modifications in place to the class/widget without returning anything new.

To reach the class/widget Many2ManyListView for been able to use extend or include functions the best way is using the following code:

var core = require('web.core');

var FieldMany2Many = core.form_widget_registry.get('many2many')

var extention_not_done = false;

FieldMany2Many.include({

init: function() {

this._super.apply(this, arguments);

//if(extention_not_done){

     if(!extention_not_done){

var Many2ManyListView = this.x2many_views.list;

// use include to modify the original

Many2ManyListView.include({

});

// or use extend to create a copy with the modifications

var Many2ManyListView_New = Many2ManyListView.extend({

});

extention_not_done = true;

}

}

});

That technique consist of using an include extension to the FieldMany2Many init and call the original init function by calling the super so the class widget will be initialized and you could then access to the original Many2ManyListView class/widget. Just need a check due the init of the FieldMany2Many will be called by many times and we don't wanna applying the extension to the Many2ManyListView several times, we just need one.

*** original answer ***

Try it this way:

var core = require('web.core');

var FieldMany2Many = core.form_widget_registry.get('many2many')

var Many2ManyListView = new FieldMany2Many(args).x2many_views.list

/*** examples ***/

Many2ManyListView.include({

});

var Many2ManyListView_New = Many2ManyListView.extend({

});

With tha code you just need to investigate what need to be passed as args for the FieldMany2Many instantiation and you will be able to call the include or extend on the retrieved Many2ManyListView 

Thanks a lot axel, frankly i was expecting an answer from you....

what i have done is returned Many2ManyListView also from form_relational(knowing that is not the correct way, but it worked somehow.)

anyway will try it soon and update u...

thanks

Pawan
on 7/9/16, 2:54 AM

One more thing, can just explain a difference between this include n extend.. how it works programmaticaly ...

Pawan
on 7/9/16, 2:56 AM

sure, let me answer your question about the difference of include and extend with an answer update since I found a direct solution to the original problem that directly works

Axel Mendoza
on 7/9/16, 3:50 AM

check it now the previous answer updates

Axel Mendoza
on 7/9/16, 5:23 AM

Thanks Axel, it worked very well, just a modification needed(inplace of "if(extention_not_done)", it should be "if(!extention_not_done)", which i have updated), rest everything is fine..

Thanks once again...

Pawan
on 7/11/16, 2:19 AM

please don't forget to accept and upvote the answer if it was helpful

Axel Mendoza
on 7/11/16, 2:21 AM

And regarding extend and include i have noticed one more thing, when we use 'extend' it is not calling the overriding method as in above case for Many2ManyListView, i was trying to override do_activate_record by extending Many2ManyListView, but it is not calling overriding method(still going with the base method),

do you have any idea why is ti happening so...?

Pawan
on 7/11/16, 2:21 AM

read carefully what I wrote about that, extend will not modify the original class/widget, it will return a new class/widget with the modifications

Axel Mendoza
on 7/11/16, 2:23 AM

oh.. ok , i missed, thanks once again...

Pawan
on 7/11/16, 2:30 AM

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

2 follower(s)

Stats

Asked: 7/8/16, 3:19 AM
Seen: 301 times
Last updated: 7/11/16, 2:43 AM