Hello guys how are you, I hope you will be fine and also enjoying this tutorial!!! In my previous post you learned about creating and installing a module in odoo.Today you will learn how to create an action menu. Before going to start our lesson we need to know about "Action Menus".
Action Menu:
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 (window, report, group etc...)
Window: This action will be used for opening a new window.
Report: For printing a report.
Group: Gather some action in one group.
How to create action menu:
Menus are complex to declare so there is <menuitem> short cut to declare ir.ui.menu and connect it to the corresponding action menu.
<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.Example:
In this example we will create action menu, and our created menu will triggering the action.
- Create an empty module, below screen shot shows the structure of the module.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>
<data>
<!-- window action -->
<!--
The following tag is an action definition for a "window action",
that is an action opening a view or a set of views
-->
<record model="ir.actions.act_window" id="example_list_action">
<field name="name">Example List Action</field>
<field name="res_model">example.model.name</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="help" type="html">
<p class="oe_view_nocontent_create">Create the first Example
</p>
</field>
</record>
<!-- top level menu: no parent -->
<menuitem id="main_example_menu" name="Main Example Menu"/>
<!-- A first level in the left side menu is needed
before using action= attribute -->
<menuitem id="example_menu" name="Example Menu"
parent="main_example_menu"/>
<!-- the following menuitem should appear *after*
its parent example_menu and *after* its
action example_list_action -->
<menuitem id="example" name="Example" parent="example_menu"
action="example_list_action"/>
<!-- Full id location:
action="module_name.example_list_action"
It is not required when it is the same module -->
</data>
</openerp>3. Add your xml file in the data file of __openerp.py__ fileIn our case it should be:'data': [
# 'security/ir.model.access.csv',
'templates.xml',
'views/example_action_menu.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).
0 comments
Post a Comment