Odoo is the world's easiest all-in-one management software. It includes hundreds of business apps:
CRM | e-Commerce | Accounting | Inventory | PoS | Project management | MRP | etc.
I would like to run some python code immediately when a user clicks a menu item. Old action-related documention mentions execute as a possible action type:
"Execute: The execution of a method on the server side"
...but there seems to be no other documentation or examples. Has anyone succeeded in doing something similar?
There is one way to run python code with click on menu item. By using server action, you can achieve this. You need to make one server action and set it as action parameter in menu item.
Here is an example:
<record id="action_make_testing" model="ir.actions.server">
<field name="name">Make Testing</field>
<field name="model_id" ref="model_res_partner" />
<field name="code">self.test_act(cr, uid, context.get('active_ids', ), context=context)</field>
In this server action, there is one field "code". You need to set method which you want to call with click on menu. Another one is "model_id". You need to set external id of model in which you define (or make) method, which you want to call. Here, I set "model_res_partner" as model_id. It means, i have defined method "test_act" in res.partner model.
<menuitem id='menu_testing' name='Testing' sequence="100" parent="base.menu_base_config"
In menuitem, you need to set external id of server action into action parameter.
Python code to run : Method name = test_act
_inherit = 'res.partner'
About This Community
This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.Register
Odoo Training Center
Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.Test it now
|Asked: 9/23/14, 5:03 AM|
|Seen: 4320 times|
|Last updated: 2/2/16, 6:43 AM|