How to do it...

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:

  1. Create the XML file to add the data records describing the user interface views/library_book.xml:
<?xml version="1.0" encoding="utf-8"?> 
<odoo> 
  <!-- Data records go here --> 
</odoo> 
  1. Add the new data file to the addon module manifest, __manifest__.py by adding it to views/library_book.xml:
{ 
    'name': "Library Books", 
    'summary': "Manage your books", 
    'depends': ['base'], 
    'data': ['views/library_book.xml'], 
} 
  1. Add the action that opens the Views in the library_book.xml file:
<act_window 
  id="library_book_action" 
  name="Library Books" 
  res_model="library.book" />
  1. Add the menu item to the library_book.xml file, making it visible to the users:
<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:

  1. Add a custom form view to the library_book.xml file:
<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>
  1. Add a custom Tree (List) view to the library_book.xml file:
<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> 
  1. Add custom Search options to the library_book.xml file:
<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>
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.253.62