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.


Call Python function from JavaScript

Ranga Dharmapriya
on 5/27/15, 12:41 AM 2,522 views

I have created function called mrp_Order and call this function when click the req button. But I got this error.

Odoo Server Error

Traceback (most recent call last):

File "D:\Odoo\odoo-v8-osm\openerp\http.py", line 530, in _handle_exception

return super(JsonRequest, self)._handle_exception(exception)

File "D:\Odoo\odoo-v8-osm\openerp\http.py", line 567, in dispatch

result = self._call_function(**self.params)

File "D:\Odoo\odoo-v8-osm\openerp\http.py", line 303, in _call_function

return checked_call(self.db, *args, **kwargs)

File "D:\Odoo\odoo-v8-osm\openerp\service\model.py", line 113, in wrapper

return f(dbname, *args, **kwargs)

File "D:\Odoo\odoo-v8-osm\openerp\http.py", line 300, in checked_call

return self.endpoint(*a, **kw)

File "D:\Odoo\odoo-v8-osm\openerp\http.py", line 796, in __call__

return self.method(*args, **kw)

File "D:\Odoo\odoo-v8-osm\openerp\http.py", line 396, in response_wrap

response = f(*args, **kw)

File "D:\Odoo\odoo-v8-osm\addons\web\controllers\main.py", line 935, in call_kw

return self._call_kw(model, method, args, kwargs)

File "D:\Odoo\odoo-v8-osm\addons\web\controllers\main.py", line 927, in _call_kw

return getattr(request.registry.get(model), method)(request.cr, request.uid, *args, **kwargs)

File "D:\Odoo\odoo-v8-osm\openerp\api.py", line 241, in wrapper

return old_api(self, *args, **kwargs)

TypeError: mrp_Order() takes at least 4 arguments (3 given)

Python code

def mrp_Order(self, cr, uid, ids, context=None):

result = {

'name': "mrpOrder",

'view_mode': 'form',

'view_type': 'form',

'res_model': 'mrp.production',

'type': 'ir.actions.act_window',

'nodestory': True,

'target' : 'new',

'context' : context,


return result

JavaScript code

function openerp_restaurant_reqbill(instance,module){

var QWeb = instance.web.qweb;

var _t = instance.web._t;


build_widgets: function(){

var self = this;



var reqbill = $(QWeb.render('PrintReqButton'));


var order = self.pos.get('selectedOrder');

if(order.get('orderLines').models.length > 0){

var receipt = order.export_for_printing();


receipt: receipt, widget: self,



new instance.web.Model("pos.order").call("mrp_Order");








a side note: you taged question with "odooV8" but function definition is in old style. take look of this post if you interested in new v8.0 API way to do the same.

on 5/27/15, 4:43 AM


| 6 5 7
Tbilisi, Georgia
On 5/27/15, 4:01 AM

you have to remove ids parameter from your function definition, or pass ids from javascript. in first case, your function definition will become:

def mrp_Order(self, cr, uid, context=None): 

-note that ids parameter is NOT present.

otherwise, when you need to have ids parameter in your function, then you've to pass ids from javascript, as first element of argument list, in your case you can pass empty array of ids (but as you don't use ids anyway in your python function, better to use above posted option):

new instance.web.Model("pos.order").call("mrp_Order", [[]]); 

-used array of argument list and it's first element is list of ids, that's going to be value of ids parameter in your python function.

On 6/17/15, 2:41 AM

For this you can use:

new instance.web.Model('pos.order').call("mrp_Order",[ [SPECIFY IDS IN LIST] ]);

Ranga Dharmapriya
On 5/27/15, 5:03 AM


interesting... it does nothing? you've had wrong call of python function, I corrected it for you and I think you have no more the error posted in your question. actually you are asking new question on the same thread, that's "how to show popup in pos?" it's a bit different then "Call Python function from JavaScript". I suggest to open new thread with "how to show popup in pos?" title, or something more close to your requirements. because of question asked and error log provided I have not read your code line by line, but I found the source of error. whereas as I see now, after you clarified your requirement to open popup... the problem is that this is not a way to open popup. I investigated your code more deeply, you simply call "mrp_Order" function, but you do nothing with result of this call. you can use such call(and do not handle result in "then()") if it does something at server side and returns nothing, i.e. for "void" functions. but if you've to handle returned value, then you should use "then()" as follows:

new instance.web.Model("pos.order").call("mrp_Order").then(function(result){
        //here result contains whatever is returned from mrp_Oder function, in your case
        //result contains: {'name': "mrpOrder", 'view_mode': 'form', 'view_type': 'form', 'res_model': 'mrp.production', 'type': 'ir.actions.act_window', 'nodestory': True, 'target' : 'new', 'context' : context,}
        //that's all. try this:
you see? you can do whatever you want with result(returned value) of mrp_Oder function in then() part, but if you expect the mrp_Order to open popup window at client side just because you call it, then I'm afraid to disappoint you, but that's not going to happen.
one more side note, I'm not familiar with pos module but pos is implemented to work independently in case of internet connection interruption. probably adding RPC call can compromise this ability, as RPC can't be done in offline mode. maybe you need something like https://github.com/odoo/odoo/blob/2ac4a3854be846a178972ecc6ee5a6318bce3995/addons/point_of_sale/static/src/js/screens.js#L359-L383 ?
on 5/27/15, 8:24 AM

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

1 follower(s)


Asked: 5/27/15, 12:41 AM
Seen: 2522 times
Last updated: 6/30/15, 3:48 AM