Odoo Help

0

How to call python function from javascript?

By
malikge
on 3/15/14, 7:27 PM 16,510 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
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>)

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.

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.

Register

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

0 follower(s)

Stats

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