官术网_书友最值得收藏!

Adding menu items

Now that we have the places to store our data, we want to have them available on the user interface. The first thing to do should be to add the corresponding menu options.

Create the views/todo_menu.xml file to define a menu item and the action performed by it:

<?xml version="1.0"?> 
<odoo> 
  <!-- Action to open To-do Task list --> 
  <act_window id="action_todo_task" 
    name="To-do Task" 
    res_model="todo.task" 
    view_mode="tree,form"
/> <!-- Menu item to open To-do Task list --> <menuitem id="menu_todo_task" name="Todos" action="action_todo_task"
/> </odoo>

The user interface, including menu options and actions, is stored in database tables. The XML file is a data file used to load those definitions into the database when the addon module is installed or upgraded. The preceding code is an Odoo data file, describing two records to add to Odoo:

  • The <act_window> element defines a client-side window action that will open the todo.task model with the tree and form views enabled, in that order
  • The <menuitem> defines a top menu item calling the action_todo_task action, which was defined before

Both elements include an id attribute. This id attribute, called an XML ID, is very important; it is used to uniquely identify each data element inside the module, and is the method other elements can use to reference it. In this case, the <menuitem> element needs to reference the action to process, and so needs to use the <act_window> XML ID for that. XML IDs are discussed in greater detail in Chapter 5, Import, Export, and Module Data.

Our module does not yet know about this new XML data file. For this to happen, it needs to be declared in the __manifest__.py file, using the data attribute. It is a list of the data files to be loaded by the module upon installation or upgrade.

Now add this attribute to the manifest's dictionary:

'data': ['views/todo_menu.xml'], 

We need to upgrade the module again for these changes to take effect. Go to the Todos top menu and you should see our new menu option available. Clicking on it displays a basic list view, and we will have available an automatically generated form view:

Even though we haven't defined our user interface view, the automatically generated list and form views are functional, and allow us to start editing data right away.

主站蜘蛛池模板: 兰考县| 胶州市| 雅安市| 鲁山县| 巫溪县| 嘉义县| 方正县| 富阳市| 怀远县| 临沭县| 芦山县| 济宁市| 姜堰市| 固始县| 宁津县| 屏东市| 上林县| 常熟市| 玉龙| 郴州市| 维西| 枣庄市| 福海县| 怀仁县| 遂宁市| 勃利县| 鹿泉市| 揭西县| 莱芜市| 花莲市| 长垣县| 新乐市| 木兰县| 浏阳市| 龙井市| 南漳县| 区。| 蓬莱市| 弥渡县| 高尔夫| 济宁市|