Aide

0

how to calling custom method python on xml rpc

Avatar
Wendra

Hi how to calling custom method python on odoo on xml rpc from android code example my method like this

def _get_salesteam_filter(self,user_id):
    job_id = self.env['hr.employee'].search([('user_id', '=', user_id)]).job_id.id
    sequence = self.env['sales_report_custom.sales_team_filter'].search([['job', '=', job_id]]).sequence
    filters = self.env['sales_report_custom.sales_team_filter'].search([['sequence', '>=', sequence]])

when i call my method on xml rpc, i have error like this

TypeError: get_salesteam_filter_mobile() takes exactly 2 arguments (1 given)

i put 2 parameter (self, user_id) on my android code

List data = Arrays.asList(new HashMap() {{ put("self",false); put("user_id",uid); }});

 

but still error, Do you have an idea ?

my guess, self parameter is not recognized

Thanks!

Avatar
Annuler
2 Réponses
2
Avatar
Axel Mendoza
Meilleure réponse

Hi Wendra

There are a couple of things in your code

1- You cannot call methods where the method name is prefixed by _ because those are like private or internal methods and Odoo check specifically for that before calling your method, so you are not calling the right method in your xmlrpc call, you are calling get_salesteam_filter_mobile and not _get_salesteam_filter who is the one that receive the user_id parameter

2- Your method for be able to be called needs a decorator responsibly for wear it with the api environment variables like db cursor and context. This decorator could be @api.multi or @api.one if your method is defined in the res.users model to no even need to define the user_id parameter because it will be bind it to self as a browse recordset, or @api.model for arbitrary data parameter like user_id for any other model distinct from res.user

3- You don't need to pass the value of self for your xmlrpc call since self is an automatic parameter for object class methods referring to the current object and also as I said before used by Odoo to bind recordsets and many other environment stuffs 

Hope this helps 

2 Commentaires
Avatar
Annuler

I was going through this too, i didn't have the right decorator. Thank you!

Avatar
Định Nguyễn
-

Many thank @Axel Mendoza

0
Avatar
Michael Mugge
Meilleure réponse

I am having this issue as well. XML-RPC is very limited. So as a work around you want to keep in mind that Odoo still supports the basic MVC paradigm.  Knowing this, I just created a controller with a little custom code to run the raw query I need and then just call that controller route from my external script (with authentication of course)

It seems to me that XML-RPC is great for the basics but at some point if you are going to start doing more advanced things, you probably just want to develop your own specific function in one or more controllers under a logical route for this purpose, such "/api' .. for example.

Avatar
Annuler