Search Here

Pages

Saturday, 19 March 2016

How to create Action Menu in Odoo

In my previous post you learned about creating and installing a module in odoo. In this article you will learn how to create an action menu. Before going to start our lesson we need to know about "Action Menus".


Action Menu in Odoo

      Menus are record in the ir.ui.menu table, and the action defines the behavior of the system in response to the action of the users. Action can be triggered by different ways, first one is by clicking on menu items for example we linked our menu with a specific action. Second is by clicking on button and the button exists on some views. 

There are different types of action (windows action, server action, scheduled action , report, group etc...)

  1. Window: This action will be used for opening a new window.
  2. Report: For printing a report.
  3. Group: Gather some action in one group.

How to create action menu in odoo

       Menus are complex to declare so there is <menuitem> short cut to declare ir.ui.menu and connect it to the corresponding action menu.

Recommend:


<record model="ir.actions.act_window" id="action_list_ideas">
    <field name="name">Ideas</field>
    <field name="res_model">idea.idea</field>
    <field name="view_mode">tree,form</field>
</record>
<menuitem id="menu_ideas" parent="menu_root" name="Ideas" sequence="10"
          action="action_list_ideas"/>
  
The action must be declared before its corresponding menu in the XML file. Below screen shot shows menu and its corresponding action.

How to create Action Menu in Odoo



ExampleIn this example we will create action menu, and our created menu will triggering the action. 
  1. Create an empty module, below screen shot shows the structure of the module.

Odoo Module Structure
 

2. Now create example_action_menu.xml file in  module_name/views folder in your created module.
/module_name/views/example_action_menu.xml

<?xml version="1.0" encoding="UTF-8"?><openerp>                                The following tag is an action definition for a "window action",            that is an action opening a view or a set of views        -->                                                                                                                        
                                     before using action= attribute -->                                               its parent example_menu and *after* its             action example_list_action -->                          example_list_action"                     action="module_name.example_list_action"             It is not required when it is the same module -->    </openerp>
3. Add your xml file in the data file of  __openerp.py__ file    


In our case it should be:
'data': [
        # 'security/ir.model.access.csv',
        'templates.xml',
                ],
Now this is the end of this tutorial, today you learned what is action menu and how to create action menus. In my next post you will learn about View (form, tree)  



No comments:

Post a comment