To add a view, we will add an XML file with its definition to the module. Since it is a new Model, we must also add a menu option for the user to be able to access it. Be aware that the sequence of the following steps is relevant, since some of them use references to IDs defined in the preceding steps:
views/library_book.xml:
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<!-- Data records go here -->
</odoo>
adding it to views/library_book.xml:
{
'name': "Library Books",
'summary': "Manage your books",
'depends': ['base'],
'data': ['views/library_book.xml'],
}
<act_window
id="library_book_action"
name="Library Books"
res_model="library.book" />
<menuitem
id="library_book_menu"
name="Library"
action="library_book_action"
parent=""
sequence="5" />
If you try and upgrade the module now, you should be able to see a new top menu option (you might need to refresh your web browser).
Clicking on it should work and will open Views for Library Books that are automatically generated by the server:
<record id="library_book_view_form" model="ir.ui.view">
<field name="name">Library Book Form</field>
<field name="model">library.book</field>
<field name="arch" type="xml">
<form>
<group>
<field name="name"/>
<field name="author_ids" widget="many2many_tags"/>
</group>
<group>
<field name="date_release"/>
</group>
</form>
</field>
</record>
<record id="library_book_view_tree" model="ir.ui.view">
<field name="name">Library Book List</field>
<field name="model">library.book</field>
<field name="arch" type="xml">
<tree>
<field name="name"/>
<field name="date_release"/>
</tree>
</field>
</record>
<record id="library_book_view_search" model="ir.ui.view">
<field name="name">Library Book Search</field>
<field name="model">library.book</field>
<field name="arch" type="xml">
<search>
<field name="name"/>
<field name="author_ids"/>
<filter string="No Authors" domain="[('author_ids','=',False)]"/>
</search>
</field>
</record>