Odoo Help


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.


How to call python function from javascript?

on 3/15/14, 7:27 PM 10,185 views

I am trying to call python function from javascript.

Python class:

class message_of_the_day(osv.osv):
   _name = "message_of_the_day"

   def my_method(self, cr, uid, context=None):
    return {"hello": "world")}

Javascript file:

openerp.oepetstore = function(instance) 
  instance.oepetstore.MyClass = instance.web.Class.extend(
    hi_start: function() 
      var self = this;
      var model = new instance.web.Model("message_of_the_day");
      model.call("my_method", [], {context: new instance.web.CompoundContext()}).then(function(result) 
        console.log("hello world, I am working");
var my_object = new instance.oepetstore.MyClass();

When I run this module, the page stopped loading.

What am I doing wrong here?

Any help???

on 3/21/14, 5:48 PM
On 1/23/15, 5:35 AM

Hi i have done with backend module .. calling odoo model from javascript . but when i try same on web ie fronted module its gives me error Referrence Error :Openerp is not define  ON => openerp.dummy = function(instance)

any idea?


@Kashif. This is an old post and your inquiry is different from the original one. I would suggest that you create your own question and post your code there.

on 1/23/15, 6:06 AM
Peter Nietz
On 8/20/14, 11:42 AM

you have to use the RPC:

ODOO Remote Procedure Calls

Use 'this', single quotes and the done function and it should work:

this._model = ...;
var x = this._model.call('my_method',[]).done(function(results){


sharjeel ali shaukat
On 8/20/14, 8:29 AM

you can use call function or get_func in javascript to call a python function. for example in javascript new instance.web.Model(<model.name.in.quotes>).get_func(<yourfunction_name>)(<arguments>)

On 8/27/14, 2:58 AM

have you manage to get it working? i have tried this for POS, and it is possible to call python from js.

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

0 follower(s)


Asked: 3/15/14, 7:27 PM
Seen: 10185 times
Last updated: 6/16/15, 5:56 AM