There's some javascript code in a module that I want to modify, is there a way to do that in a module, like in python ?
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Accounting
- Inventory
- PoS
- Project management
- MRP
This question has been flagged
Yes!
First You'll need to create your own module, and set the module you want to modify as a dependency of your new module in the __openerp__.py
file : 'depends': ['module_I_want_to_extend'],
Then you need to create your javascript file, and put it in the standard place : module/static/src/js/file.js
and then add to the list of js files to load in __openerp__.py
: js:['static/src/js/file.js'],
file.js
will be executed after the code of the module you want to extend, so you have the oportunity to redefine and modify everything you want. Here's a sample js file that overrides the bar()
method of the Foo
class of the sample
module.
openerp.new_module = function(instance){
var module = instance.sample // loading the namespace of the 'sample' module
module.Foo.include({
bar : function(){
console.log('Hello!');
this._super(); // calling the original Foo.bar() method
},
});
};
That'll work, but... if the Foo class has sub classes, those sub classes will not inherit your modifications. If you need to do that, you can use include() instead of extend().
That is true, I'll edit the answer ( I originally used module.Foo.extend({...}) )
You got an error in the code example : module.Foo = module.Foo.include({...
will assign undefined
to module.Foo
. You just have to use module.Foo.include({...
alone, this will "edit in place"
owkay ! edited.
I have a situation when my module loads I want to make a call to another module which is not jet in instance object. Is there any way to delay initialization of my module till all other modules are in instance object?
The technical documentation is located here:
In the web part, you will find documentation on how to write web modules and some reference documentation.
After that, there are many tricks to override a module behavior. A typical one would be to use the Class.include() method to modify an existing class, overriding whatever methods it defines.
Oh, and by the way, the answer above (cannot edit...) Only works if module.Foo
extends instance.web.Class
native JS objects, or Backbone objects do not provide an include()
method. So you have to do it by hand.
openerp.new_module = function(instance){
var module = instance.sample; // loading the namespace of the 'sample' module
var _super_ = module.Foo.prototype.bar;
module.Foo.prototype.bar = function(){
console.log('Hello!');
_super_.call(this);
};
};
Hello, I am trying to inheriting var Pos from point_of_sale from openerp 6.1 module to override get_app_data() function please help me. Here is my code for referance which gives error "module is undefined": This is my inherited js file:
openerp.my_pos = function(instance){
instance.my_pos = {};
var module = instance.point_of_sale;
var _super_ = module.Pos.prototype.get_app_data;
module.Pos.prototype.get_app_data = function(){
console.log('Hello!');
_super_.call(this);
};
};
How to load js, in the web/database/manager form?
It seems this doesn't work on login form or before login
I even started odoo with --load web,mymodule adding .js in assets and they are not loaded.