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

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.

主站蜘蛛池模板: 龙州县| 肃南| 石屏县| 漠河县| 宁河县| 商洛市| 怀远县| 三都| 汉源县| 高尔夫| 禹城市| 山阳县| 赞皇县| 闸北区| 竹山县| 新宁县| 高雄市| 金山区| 安庆市| 湘阴县| 濮阳县| 娄底市| 沙田区| 亚东县| 尼勒克县| 德令哈市| 牙克石市| 塔城市| 新营市| 沐川县| 宝兴县| 伊川县| 文水县| 手机| 阳新县| 阿克| 天门市| 大丰市| 龙陵县| 沂源县| 泸水县|