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

How to call python function from javascript?

By
malikge
on 3/15/14, 7:27 PM 10,918 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();
my_object.hi_start();
}

When I run this module, the page stopped loading.

What am I doing wrong here?

Any help???

malikge
on 3/21/14, 5:48 PM
1
kashif
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.

Ivan
on 1/23/15, 6:06 AM
1
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){
  whatever;    
});
 

 

0
ahmad
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.

0
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>)

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)

Stats

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