Adding list and search views

When viewing a model in list mode, a <tree> view is used. Tree views are capable of displaying lines organized in hierarchies, but most of the time they are used to display plain lists.

We can add the following tree view definition to todo_view.xml:

<record id="view_tree_todo_task" model="ir.ui.view">
  <field name="name">To-do Task Tree</field>
  <field name="model">todo.task</field>
  <field name="arch" type="xml">
    <tree colors="gray:is_done==True">
      <field name="name"/>
      <field name="is_done"/>
    </tree>
  </field>
</record>

We have defined a list with only two columns, name and is_done. We also added a nice touch: the lines for done tasks (is_done==True) are shown in grey.

At the top right of the list Odoo displays a search box. The default fields it searches for and available predefined filters can be defined by a <search> view.

As before, we will add this to the todo_view.xml:

<record id="view_filter_todo_task" model="ir.ui.view">
  <field name="name">To-do Task Filter</field>
  <field name="model">todo.task</field>
  <field name="arch" type="xml">
    <search>
      <field name="name"/>
      <filter string="Not Done"
              domain="[('is_done','=',False)]"/>
      <filter string="Done"
              domain="[('is_done','!=',False)]"/>
    </search>
  </field>
</record>

The <field> elements define fields that are also searched when typing in the search box. The <filter> elements add predefined filter conditions, using domain syntax that can be selected with a user click.

..................Content has been hidden....................

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