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

Redefine Web chrome.js and view_form.js

By
Carlos Almeida
on 11/3/15, 11:39 PM 779 views

I was able to reach this point, my NEW.js script file is loaded in /web/database/manager page.

If I create a break point in "var break_point;" it stops there.

I don't get any error, but it just don't execute the rest of the code...

openerp.MYMODULE = function (instance) {
/*just for test in a break point*/
var break_point;
/* redefine from chrome.js:412 */
instance.web.DatabaseManagerNEW = instance.web.DatabaseManager.extend( {
do_render: function() {
this._super(parent);
/* add new submit handler*/
self.$el.find("form[name=NEW_db_form]").validate({ submitHandler: self.do_NEW });
},
do_NEW: function(form) {
var self = this;
var $form = $(form),
fields = $form.serializeArray();
self.rpc("/web/database/NEW", {'fields': fields}).done(function(result) {
if (result.error) {
self.display_error(result);
return;
}
self.start();
});
},
});
/* redefine view_form.js:72 */
instance.web.FormViewNEW = instance.web.FormView.extend({
load_form: function(data) {
this._super(parent);
/* redefine button */
if (!this.sidebar && this.options.$sidebar) {
this.sidebar.add_items('other', _.compact([
self.is_action_enabled('create') && { label: _t('NEW'), callback: self.on_button_NEW }
]));
}
},
on_button_NEW: function() {
var self = this;
return this.has_been_loaded.then(function() {
return self.dataset.call('copy', [self.datarecord.id, {}, self.dataset.context]).then(function(new_id) {
self.record_created(new_id);
self.to_edit_mode();
});
});
},
});
};

This code inserted in those files works, but not in my NEW.js file.

Hi Carlos,
how and when you need to use that new widgets that you are creating?. Note that when you use extend you are creating a new widget and normally you need to use it with a qweb client template and/or use it through a client action or a new kind of view. What is the need for those new widgets?. I think that the reason that your code is not working relies in that questions.
Provide more info about what you need to do to be able to help you. I you just wanna change the behavior of the original widget you need to use 'include' not 'extend'. The difference is that include change the widget in place and extend return a copy of the widget with the changes

Axel Mendoza
on 11/4/15, 2:08 AM
2

Parikshit

--Parikshit--
939
| 6 3 8
Ahmedabad, India
--Parikshit--

Working as an OpenERP/Odoo developer both experience in web and addons. you can contact me at:

E-mail : parikshitvaghasiya@gmail.com

Blog : parikshitvaghasiya.blogspot.in

Stackoverflow : http://stackoverflow.com/users/5089106/parikshit-vaghasiya

Parikshit
On 11/4/15, 12:29 AM

Hello,

you have to return super by method like this :

instance.web.DatabaseManagerNEW = instance.web.DatabaseManager.extend( {
     do_render: function() {
         /* add new submit handler*/
         self.$el.find("form[name=NEW_db_form]").validate({ submitHandler: self.do_NEW });
         return this._super();
    }, do_NEW: function(form) { var self = this; var $form = $(form), fields = $form.serializeArray(); self.rpc("/web/database/NEW", {'fields': fields}).done(function(result) { if (result.error) { self.display_error(result); return; } self.start(); });
         return this._super(form); }, })


Hope this will help you!!

not working, I've even relpaced all "self" by "this". could it be new entities names? should be equal? or change the function names (ex:. do_render to do_render_new)?

Carlos Almeida
on 11/4/15, 12:52 AM

thanks, it was some js errors, ubt that _super() helped a lot

Carlos Almeida
on 11/4/15, 3:03 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: 11/3/15, 11:39 PM
Seen: 779 times
Last updated: 1/19/16, 9:43 PM