Adding menu items
Now that we have the places to store our data, we want to have it available on the user interface. The first thing to do is add the corresponding menu options.
Edit the views/library_menu.xml file and, inside the <odoo> XML element, add the records that define a menu item and the action performed by it:
<!-- Action to open the Book list --> <act_window id="action_library_book" name="Library Books" res_model="library.book" view_mode="tree,form"
/> <!-- Menu item to open the Book list --> <menuitem id="menu_library_book" name="Books"
parent="library_menu" action="action_library_book"
/>
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 library.book model with the tree and form views enabled, in that order
- The <menuitem> defines a top menu item that calls the action_library_book action, which was defined before
We now need to upgrade the module again for these changes to take effect. Then, after a browser-page refresh, we should see the Library top menu, and it should have a submenu option available. Clicking on it displays a basic list view, and records can be edited using an automatically-generated form view. We can see it if we click on the Create button:
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.