An Overview of List View Parameters in Odoo 17

TEENA
August 3, 2024
list-view-parameters-in-odoo

In Odoo, various view types, such as Kanban, form, graph, tree, pivot, search, and calendar, play a crucial role in making the platform more user-friendly by showcasing records in different formats.

This blog post will delve into creating a list view and the various parameters utilized in the odoo list view to optimize performance.

To illustrate, let’s begin by establishing a model, 'student. student', and specifying its fields.

class Student(models.Model):

_name = 'student.student'

          number = fields.Char('Name', default=lambda self: _('New'),copy=False,                                                  readonly=True, tracking=True)

          name = fields.Char(string='Student')

          roll_number = fields.Integer(copy=False,string='Roll Number')

          age = fields.Float(string='Age')

          email = fields.Char(string='Email')

          class_number = fields.Float(string='Class')

          teacher = fields.Many2one('class.teacher', string='Teacher')

          grade = fields.Float(string='Grade')

          state = fields.Selection(

                   [('excellent', 'Excellent'),

                   ('good', 'Good'),

                   ('average', 'Average'),

                   ('pass',         'Pass'),

                   ('fail', 'Failed')])
After setting the action for the model, we can specify the tree structure in the view mode of it. actions.act_window records.
<record id="student_action_test" model="ir.actions.act_window">

<field name="name">Student Mark</field>

<field name="type">ir.actions.act_window</field>

<field name="res_model">student.student</field>

<field name="view_mode">tree,form</field>

</record>

In the ir_ui_view model, we can now create a new record. This involves specifying the ID and name, as well as the associated model for which the view record is intended. Additionally, we define the structure of the view record. To specify the fields within the <tree> tag, we work within the architecture.

<!--Student tree view -->

<record id="student_student_view_tree" model="ir.ui.view">

<field name="name">student.student.view.tree</field>

<field name="model">student.student</field>

<field name="arch" type="xml">

<tree string="Student">

          <field name='roll_number'/>

          <field name='number'/>

          <field name="name" decoration-bf="1"/>

          <field name="age"/>

          <field name="email"/>

          <field name='teacher'/>

          <field name="grade"/>

          <field name='state'/>

</tree>

</field>

</record>

It generates the tree view displayed in the user interface.

odoo-list-view

To enhance the visual appearance of the list view data, we can utilize the ‘decoration’ attribute to apply various colours. The available attributes and their corresponding colours are as follows: –

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

<tree string="Student"

decoration-success="state == 'excellent'"

decoration-info="state == 'good'"

decoration-danger="state == 'fail'"

decoration-warning="state == 'average'">

</tree>

The outcome is that the lines in the tree view are displayed in various colours according to our specified conditions.

2. Editable: This feature allows for the tree view to be modified, offering two options: bottom and top.

<tree string="Student" editable="bottom">

Consequently, we can insert a new line at the end of the list view.

views-in-odoo

By setting editable to “top,” we enable editing at the beginning of the list view.

<tree string="Student" editable="top">

The accompanying screenshot illustrates the capability to add a new line at the top.

list-view-in-odoo

3. Limit: The list view displays a maximum of six records at a time. To view the seventh record, simply click on the right arrow icon as indicated in the screenshot.

<tree string="Student" limit="6">

4. Create: By default, the creation of new records is disabled. This is illustrated in the screenshot where the user does not have the option to create new records.

<tree string="Student" create="False">
list-views-in-odoo

5. Delete: We can safeguard records from being deleted. The delete button is set to “True” by default.

<tree string=”Student” delete=”False”>

6. multi_edit: The multi_edit parameter enables users to make edits to multiple records simultaneously. In the screenshot, the user can select the records to be edited, choose the relevant column, and input the new value.

Afterwards, a confirmation dialogue box will appear. To proceed with editing the records, simply click on “Confirm”. The records will then be successfully edited.

7.Open_form_view: This parameter allows for the opening of a form view if the record is editable in the tree view. For instance, if the tree view is editable and the user wishes to view the corresponding form view, the ‘open_form_view’ parameter will add a view button to the last column of the list view in odoo.

<tree string="Student"  editable="bottom"  open_form_view="True">
The following screenshot depicts that the user can see the form view of the corresponding record by clicking the ‘view’ button.

8. default_order: The default_order parameter is utilized to determine the sorting options for the list. We have the ability to indicate the field that will serve as the sorting parameter and whether it should be in ascending or descending order.

<tree string=”Student” default_order=”roll_number desc”>

The image below illustrates that the entries in the tree view are arranged in descending order according to the roll number.

9. default_group_by: The default_group_by parameter is employed to group the records in the tree view. In this case, we can specify the field that will be used to group the records.

<tree string=”Student” default_group_by=”teacher”>

Expand: The expand parameter facilitates the examination of records within their corresponding groups.

groups_limit: The groups_limit parameter assists in establishing the number of groups displayed on each page.

<tree string=”Student” default_group_by=”teacher” expand=”1″ groups_limit=”2″>

"Unlock the Full Potential of Your Business with Odoo ERP!"

"Get a Cost Estimate for Your ERP Project, Absolutely FREE!"

Get a Free Quote

Leave a Reply

Your email address will not be published. Required fields are marked *