1
votes

I've defined a server action in Odoo 10. It's easy to create a button in a view to call that server action by using the server actions ID. For example, if there server action's ID was 123:

<button name="123" type="action" string="Run Action"/>

Is there any way to call this action via the API? I'm not sure how to do this since the server action does not have a method name. It's just an ID. I also need to able to pass context to the action. Is this possible?

1
By the API you mean XML/JSON RPC?Naglis
Yes I mean the xml rpc APIflyingL123

1 Answers

2
votes

In Odoo's base module the model ir.actions.server is defined (base/ir/ir_actions.py). There is a method called run which should be callable from the XMLRPC API.

To use a context, just add it on the call as keyword parameter (kwargs) named context, like:

models.execute_kw(db, uid, password,
    'res.partner', 'check_access_rights',
    ['read'], {'raise_exception': False, 'context': {'test': True}})

(Example was extended from the official example 'Calling Methods')

It seems to be a bit magic, but it's done here.