Odoo Help


How do I call a python function from a JS file in Odoo v8?

Gopakumar N G
on 3/17/15, 1:45 AM 5,440 views

I have created a new module in Odoo v8 and created one template in it. For that template based on some values I need to call a python method from a JS file. I have tried the following methods:


function openerp_pos_models(instance){

var myModel = new instance.web.Model('my.model');


but on loading the page it shows instance is not defined?

2) var Users = new openerp.web.Model('res.users');

this one shows Uncaught ReferenceError: openerp is not defined and Uncaught TypeError: Cannot read property 'Model' of undefined.

How can call a method from a JS file in odoo v8? The above methods are working in v7 and v8 base modules.

me too want to know.. this.

on 3/19/15, 2:25 AM

You should make Ajax /jQuery calls from the Javascript to the Python method. Have a look at http://stackoverflow.com/questions/13175510/call-python-function-from-javascript-code this for example. Should be working in Odoo too.

on 3/20/15, 4:44 AM

Akhil P Sivan

--Akhil P Sivan--

| 5 4 7
Kochi, India
--Akhil P Sivan--

Interested in exploring Odoo both technically & functionality wise.

email-id : akhilpsivan01@gmail.com

Akhil P Sivan
On 3/24/15, 9:18 AM


You need to define the instance for your custom module like this:

Here, "custom_module" is the folder name of your module. And here I have just created a widget. And you can call a python method using the call() function as shown in example. Just mention the name of method(eg: "action_test"), which is defined in your model. After method name, the second arguement is used pass some context if any.

For example:

in .py file

class custom_module(models.Model):

_inherit = "product.product"


def my_method(self):

      return {"hello": "world"}

in .js file

openerp.custom_module = function(instance, local) {

      var _t = instance.web._t,

      _lt = instance.web._lt;

      var QWeb = instance.web.qweb;

      local.WidgetName = instance.Widget.extend({


              start: function () {

               this.$el.append(QWeb.render("YourTemplateName",{name: "Your name"})); // this is another way of selecting template and pass values in context to that template


                    var self = this;

                    var model = new instance.web.Model("product.product");

                    model.call("my_method", {context: new instance.web.CompoundContext()}).then(function(result) {

                    self.$el.append("<div>Hello " + result["hello"] + "</div>");




instance.web.client_actions.add('your.object', 'instance.custom_module.WidgetName');

It shows the following error: ""Uncaught TypeError: Cannot read property 'web' of undefined "" from the following line: return new instance.web.Model('product.product')

Gopakumar N G
on 4/13/15, 3:31 AM

About This Community

This platform 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.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 3/17/15, 1:45 AM
Seen: 5440 times
Last updated: 4/13/15, 10:21 PM