Enable Dark Mode!
list-view-parameters-in-odoo-12.png
By: Vinaya Suresh

List View Parameters in Odoo 12

Technical Odoo 12 Sales

In Odoo, views are ways via which models/objects get displayed to the end-user. Views of different types and each view represent a mode of visualization, and these turn the modules more user-friendly. Several types of views are used in Odoo and they are like tree, form, search, calendar, graph, pivot, Kanban, and so forth.

As the names of the views are different, the views are also different. For instance, a ‘tree’ view provides a list view of objects, and a ‘Form’ view displays a single object.

Tree View in Odoo is one of the commonly seen representational views of Odoo

In this blog, let us see how to create a list view and perform various operations on the list view. In order to create a list view, define the fields needed to be displayed in the list view in a model. So now let us create a model say for example ‘sales. person’ to track the products sold:

class SalesPerson(models.Model):
_name = 'sales.person' 
_description = 'Sales Person'
name = fields.Char(string='Name', required=True)
code = fields.Char(string='Code')
email = fields.Char('Email', required=True)
mobile = fields.Char('Mobile', required=True)
products = fields.Integer("Number of Products")

Now define a record to view the list view as shown below:

<record id="view_sales_person" model="ir.actions.act_window">	
 <field name="name">Sales Person</field>	
 <field name="res_model">sales.person</field>	
 <field name="view_type">form</field>	
 <field name="view_mode">tree,form</field>	
 <field name="view_id" ref="view_sales_tree"/>		
 <field name="domain">[]</field>	
 <field name="help" type="html">	
 <p class="oe_view_nocontent_create">Create Sales Persons	
 </p>	
 </field>
</record>

List the fields required in the list view:

<record id="view_sales_tree" model="ir.ui.view">
<field name="name">sales.person.tree</field>
<field name="model">sales.person</field>
<field name="arch" type="xml">
<tree string="Sales Person">	
<field name="code"/>	
<field name="name"/>	
<field name="mobile"/>	
<field name="email"/>	
<field name="products" sum="Total"/>	
</tree>     	
</field>
</record>

The list view of the above code is shown below:

list-view-parameters-in-odoo-12-cybrosys


<tree> is the root element used in the list view.


‘sum‘ is used to display the total number of products.


Similarly, avg can be calculated as:


<field name="products" avg="Total"/>


It is possible to add colors to the list view data. One can make use of the decorators for this purpose. Say for example in order to colour the data with the products less than 50.


<tree decoration-danger="products &lt;= 50" decoration-success="products &gt;= 50" string="Sales Person">


list-view-parameters-in-odoo-12-cybrosys


Decorators are used to adding decorations to the list view.

Various decorators are available to add the colours. Some of them are listed below:

decoration-bf - BOLD

decoration-it - ITALICS

decoration-danger - LIGHT RED

decoration-info - LIGHT BLUE

decoration-muted - LIGHT GRAY

decoration-primary - LIGHT PURPLE

decoration-success - LIGHT GREEN

decoration-warning - LIGHT BROWN


Sorting of records can be performed in list view using the tag default_order.


<tree decoration-danger="products &lt;= 50" decoration-success="products &gt;= 50" default_order="products" string="Sales Person">


list-view-parameters-in-odoo-12-cybrosys


The following other attributes can be used in the list view:


> editable: The editable attribute can be used to make a list view editable.


Example: <tree string="Sales Person" editable="top">


The top and bottom values are available for the editable attributes.


list-view-parameters-in-odoo-12-cybrosys


> delete: The attribute disables the action of deleting the list view record.

Example: <tree string="Sales Person" delete="false">


> create: The attribute disables the option for creating a new record.

Example: <tree string="Sales Person" create="0">


> edit: The edit declines the functionality to edit the list view

Example: <tree string="Sales Person" edit="0">


> String: Other labels for the list view.


> limit: The limit attribute helps to limit the number of records that should appear in the tree view.

Example: <tree string="Sales Person" limit="50">


Many other child attributes can be used with the list view like:


> button: The button tag is used to add the button in the list view.

Example: <button string="Ok" class="oe_highlight" type="object" name="done"/>


The ‘type’ indicates the behavior of the button.


The ‘icon’ helps to specify the icon to be displayed within the button.


If you need any assistance in odoo, we are online, please chat with us.



1
Comments

Salem Alzubaidi

how can acsess to item in list view py python code in odoo in field m2m

02/03/2022

-

4:42PM



Leave a comment

 


whatsapp
location

Calicut

Cybrosys Technologies Pvt. Ltd.
Neospace, Kinfra Techno Park
Kakkancherry, Calicut
Kerala, India - 673635

location

Kochi

Cybrosys Technologies Pvt. Ltd.
1st Floor, Thapasya Building,
Infopark, Kakkanad,
Kochi, India - 682030.

location

Bangalore

Cybrosys Techno Solutions
The Estate, 8th Floor,
Dickenson Road,
Bangalore, India - 560042

Send Us A Message