Chapter 6 - Odoo 15 Development Book

List Views

In odoo, views are mainly for visualization and it is more user friendly. When defining a view, you can specify how it will look like. There are different views in odoo, that are giving different visualizations. List view is a type of view that is like a tree or list structure. And also you can see multiple records in a single view.

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

class HospitalManagement(models.Model):
    _name = 'hospital.patient'
    _description = 'Patient'
    _inherit = ['mail.thread', 'mail.activity.mixin']
    gender = fields.Char(string='Gender', required=True, index=True)
    age = fields.Float(string='Age', required=True, index=True)
    description = fields.Html()
    active = fields.Boolean(default=True)
    partner_name = fields.Char(string='Patient')
    phone = fields.Char(string='Phone Number')
    partner_email = fields.Char(string='Email',readonly=False,
    doctor_id = fields.Many2one('hr.employee', string='Doctor')

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


First define the action window for the views.

<record id="hospital_patient_action_main_tree" model="ir.actions.act_window">
  <field name="name">Patients</field>
  <field name="res_model">hospital.patient</field>
  <field name="view_mode">list,form</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.

List view:

<record id="hospital_patient_view_tree" model="ir.ui.view">
  <field name="name">hospital.patient.tree</field>
  <field name="model">hospital.patient</field>
  <field name="arch" type="xml">
    <tree string="Cases">
      <field name="partner_name" string="Patient" />
      <field name="age"/>
      <field name="gender"/>
      <field name="phone"/>
      <field name="partner_email"/>

Here tree is the root element for a list view, inside the tree tag you can give the fields which you want to display on the tree view or list view. If you want to make the tree view editable, for that use the editable attribute.

i.e., , top and bottom values are available for this attribute.

You can use delete=False, for disabling the deletion of the record.

create=0 is used for disabling the creation of the record.

edit=0 for disabling the editing of the record.

You can set a limit for the tree view, ie, if we set limit=50 then only 50 records will be displayed on 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