Views define how records are presented to end users. You can make your modules more user-friendly by using views. Odoo consists of multiple views such as Kanban, Forms, Charts, Tree, Pivot, Search, and Calendar.
In this blog, you will learn how to create a list view and perform various operations on it.
For example, let’s create the model Book.Book.
class Book(models.Model):
_name = "book.book"
_description = "Book"
name = fields.Char(string='Name', required=True)
price = fields.Integer(string="Price")
author = fields.Char(string="Author")
category = fields.Char(string='Category')
<record id="view_book" model="ir.actions.act_window">
<field name="name">Books</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">book.book</field>
<field name="view_mode">tree,form</field>
<field name="domain">[]</field>
<field name="help" type="html">
<p class="o_view_nocontent_smiling_face">
Create Books
</p>
</field>
</record>
List the fields in the list view:
<record id="view_book_tree" model="ir.ui.view">
<field name="name">book.book.tree</field>
<field name="model">book.book</field>
<field name="arch" type="xml">
<tree string="Books">
<field name="name"/>
<field name="author"/>
<field name="category"/>
<field name="price"/>
</tree>
</field>
</record>
List view is shown below:
You can assign different colors to list view data.
<tree string="Books" decoration-danger="category == 'Tragedy'" decoration-success=" category == 'Novel'">
Decorators for adding different colors:
decoration-it – ITALICS
decoration-bf – BOLD
decoration-danger – LIGHT RED
decoration-primary – LIGHT PURPLE
decoration-info – LIGHT BLUE
decoration-warning – LIGHT BROWN
decoration-muted – LIGHT GRAY
decoration-success – LIGHT GREEN
1) editable: Used to make a list view editable
Example: <tree string=”Student” editable=”top”>
2) limit: Limiting the number of records in the list view
Example: <tree string=”name” limit=”50″>
3) delete: Disables the action of deleting
Example: <tree string=”Student” delete=”false”>
4) create: Disables the creation of a new record
Example: <tree string=”Student” create=”0″>
5) edit: Declines the option to edit the list view
Example: <tree string=”Student” edit=”0″>
In summary, ListView is one of the best views available in the Odoo platform, giving users good insight into all operational menus and can be configured as needed based on company operational parameters.