Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
8 Odpovědi
26094 Zobrazení

 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
}
)
}
Avatar
Zrušit

Is instance_id a string?

Yes, instance_id is a string.

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

Nejlepší odpověď

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):
     ...

Avatar
Zrušit
Nejlepší odpověď

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

Avatar
Zrušit
Nejlepší odpověď

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



Avatar
Zrušit
Autor Nejlepší odpověď

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.

Avatar
Zrušit

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

Related Posts Odpovědi Zobrazení Aktivita
2
kvě 24
2506
0
úno 23
2271
1
kvě 23
2159
3
dub 23
14049
2
led 23
5321