跳至内容
菜单
此问题已终结
8 回复
25966 查看

 I have a method in an Odoo 11 model that takes a single parameter and I am trying to call it using an RPC, but I am not able to send a value for that parameter. I have verified that my javascript changes (using Google Chrome's DevTools), but no matter what I do, I seem to get this same error:

process_feed_list() missing 1 required positional argument: 'instance_id'

So, it looks like the PRC is working, but for some reason it is not passing my 'arg' to the method.  My assumption is that the 'args' of the RPC are passed to the method as parameters, but that doesn't seem to be the case. 

Here are a couple of my attempts.

Based on https://www.odoo.com/documentation/11.0/reference/javascript_reference.html I tried:


refresh_feed1: function() {
var ret = this._rpc({
model: 'amazon.feed',
method: 'process_feed_list',
args: [ '1' ],
});
this.trigger_up('reload');
return ret;
}

And, using https://stackoverflow.com/questions/47194770/how-to-call-python-function-in-jquery-in-odoo-11 as a template I tried:

refresh_feed1: function( ) {
rpc.query({
model: 'amazon.feed',
method: 'process_feed_list',
args: [ { 'instance_id': '1' } ]
} ).then(
function( returned_value ){
this.trigger_up( 'reload' )
return returned_value
}
)
}
形象
丢弃

Is instance_id a string?

Yes, instance_id is a string.

I have the same issue. Have you solved it somehow?

最佳答案

var rpc = require('web.rpc')

rpc.query(

     model: //your model,

     method: //your method,

      args: [{

          'arg1': value1,

      }]

 }).then(function (result) { 

            // your code 

  });


on model.py

@api.model
def your_method(self):
     ...

形象
丢弃
最佳答案

After few days of brainstorm, trials and errors I finally managed it to work. You need to pass as arguments not

[{'instance_id': 1}]

but

[[], 1]

I have no idea why it works like this. I have a code like yours and it works... but for my module I had to change like this

形象
丢弃
最佳答案

Hi everyone,

I have the same issue, wanna call my @api.model and my browser return some errors (web/dataset/call_kw):

"Failed to load resource: the server responded with a status of 500 (INTERNAL SERVER ERROR)"

Something bad !!!

// My Python3 Class

Class ProductTemplate(model.Model):

  _inherit = '''product.template'''

  @api.model

  def say_something(self):

   view_id = self.env.ref('mymodule.action_get_something_view').read()[0]
   return {
     'name': _(view_id.name) if view_id else '',
     'type': view_id.type if view_id else '',
     'views': [(view_id.id,'tree')],
     'view_type': view_id.view_type if view_id else '',
     'view_mode': view_id.view_mode if view_id else '',
     'res_model': view_id.res_model if view_id else '',
     'res_id': self.id,
     #    'context':{},
     'target': 'new',
 }    


JS FILE 

_onClick: function(){

    return rpc.query({

      model: 'product.template',

     method: 'say_something'                                                                                                                                                                                             }).then(function(result){ console.log('Good');}).fail(function(){ console.log('Something bad !!!')});                          

} ,

Same with this._rpc.

Odoo V12.

TRIGGER_UP ???

Thanks



形象
丢弃
编写者 最佳答案

Hilar,

I am not sure how your solution is different than what I have in my second example? Please explain.


Dmitriy,

Hilar was correct, I needed the model decoration on my python method for this to work. So add:

@api.model
def method_name( self, param1, param2 )

 Sorry, I forgot to update this post that it worked.

形象
丢弃

yes check your function defined on your model and with which decorator

相关帖文 回复 查看 活动
2
5月 24
2364
0
2月 23
2128
1
5月 23
2046
3
4月 23
13880
2
1月 23
5227