This question has been flagged
6 Replies
23873 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;

module.PosWidget.include({

build_widgets: function(){

var self = this;

this._super();

if(this.pos.config.iface_raqbill){

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

reqbill.click(function(){

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

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

var receipt = order.export_for_printing();

self.pos.proxy.print_receipt(QWeb.render('BillReceipts',{

receipt: receipt, widget: self,

}));

}

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

});

reqbill.appendTo(this.$('.control-buttons'));

this.$('.control-buttons').removeClass('oe_hidden');

}

},

});

}

Avatar
Discard

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.

Best Answer

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.


Avatar
Discard
Best Answer

For this you can use:

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

Avatar
Discard
Best Answer


In Javascript

odoo.define('custom_module.my_javascript', function (require) {"use strict"; 
var Model = require('web.Model')

var custom_model = new Model('custom.model')
custom_model.call('my_function')

});

In Python

from odoo import models, fields, api 

class CustomModel(models.Model):
_name = 'custom.model'
     # .............

@api.model
def my_function(self):
        print 'fooooooooooooooo'
Watch this on YouTube !

It is working in Odoo 10


Avatar
Discard

But not in odoo 11, because Odoo 11 doesn't have web.Model. Any suggest for Odoo 11?

Author Best Answer

 

Avatar
Discard

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:
        console.log(result)
    }); 
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 ?