Odoo 16 Development Book

List Views

In Odoo, views are mainly for visualization, and it is more user-friendly. You can describe a view's appearance while defining it. In Odoo, there are various views that offer various visualizations. A form of view called a list view resembles a tree or list structure.

Furthermore, you can view numerous records on a single screen.

For creating a list view, first, you want to define a model and its fields. I.e.,

class PatientInfo(models.Model):
   _name = 'patient.info'
   _description = 'Patient Information'
   name = fields.Char(string="Name")
   age = fields.Char(string="Age")
   gender = fields.Char(string='Gender')
   phone = fields.Integer(string="Phone")
   partner_email = fields.Char(string="Email")
   doctor_id = fields.Many2one('res.partner')

Here defined a new model hospital. Patient and also created new fields for the model. Then the next step is to define a view from XML.


First define the action window for the views.

<record id="patient_action" model="ir.actions.act_window">
            <field name="name">Patient</field>
            <field name="res_model">patient.info</field>
             <field name="help" type="html">
         <p class="o_view_nocontent_smiling_face">
           No patients found. Let's create one!
         <p>To get things done, use activities and status on patients.
            <field name="view_mode">tree,form</field>

List view:

<record id="patient_info_tree" model="ir.ui.view">
            <field name="name">patient.info.form</field>
            <field name="model">patient.info</field>
            <field name="arch" type="xml">
                    <tree string="cases">
                         <field name="name"/>
                            <field name="age"/>
                            <field name="gender"/>
                        <field name="phone"/>
                            <field name="partner_email"/>
                            <field name="doctor_id"/>

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. Use the editable attribute to make the tree view editable if you wish to. For this characteristic, top and bottom values are possible. To prevent the deletion of the record, use delete=False.To prevent the creation of the record, use create=0.edit=0 stops the record from being edited. For example, if we set limit=50, then only 50 records will be shown in the tree view. You can set a limit for the tree view.



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