Development Book V17: List Views

In Odoo, views primarily serve the purpose of visualization, enhancing user-friendliness. When defining a view, you have the ability to describe its appearance. Odoo provides various views that offer diverse visualizations, and one such view is the list view, resembling a tree or list structure.

Moreover, a list view allows the display of multiple records on a single screen. To create a list view, the initial step involves defining a model and its fields.

class HospitalPatient(models.Model):
   _name = "hospital.patient"
   _description = 'Hospital Patient'
   name = fields.Char(string='Name', help='Name of Patient')
   age = fields.Integer(string='Age', help='Age of Patient')
   email = fields.Char(string='Email', help='Email of Patient')
   phone = fields.Char(string='Phone', help='Phone of Patient')
   state = fields.Selection([
       ('draft', 'Draft'),
       ('confirmed', 'Confirm'),
       ('cancel', 'Canceled')
   ], string='State', readonly=True, help='Email of Patient')

Having defined a new model "hospital.patient" and created new fields for the model, the subsequent step involves defining a view through XML in Odoo.

<record id="hospital_patient_view_tree" model="ir.ui.view">
   <field name="name">hospital.patient.view.tree</field>
   <field name="model">hospital.patient</field>
   <field name="arch" type="xml">
           <field name="name"/>
           <field name="age"/>
           <field name="email"/>
           <field name="phone"/>

Here, the tree element serves as the list view's root element, and you can specify the fields you wish to see on the tree view or list view inside the tree tag.

The user interface displays the tree view for the "hospital.patient" model as depicted below.



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



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



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

Send Us A Message