-
Create a directory named
views
in the module and create a file namedpatient_view.xml
. Add thexml
file path in the__manifest__.py
.'data': [ 'security/ir.model.access.csv', 'views/patient_view.xml', ]
-
Add the basic block in the
patient_view.xml
file:<?xml version="1.0" encoding="utf-8"?> <odoo> </odoo>
All the code will be placed inside the
odoo
tag. -
Add below code to create root menu, a menu and a sub-menu. In the root menu we can add
web_icon
as app icon and we have to create directory and file pathstatic > description > icon.png
.<!-- for root menu --> <menuitem id="hospital_root" name="KM Hospital" web_icon="km_hospital,static/description/icon.png"/> <!-- for Patients menu --> <menuitem id="hospital_patient" name="Patients" parent="hospital_root" groups="km_hospital.group_hospital_admin" sequence='5'/> <!-- for All Patients sub-menu --> <menuitem id="hospital_patient_all" name="All Patients" parent="hospital_patient" action="all_patient_action" sequence='6'/>
- Try to add two more sub-menu for
Male Patients
andFemale patients
. - Check out the code for menus
Check the menuitem if it has been created or not. Go to
Settings > Technical > Menu items
Search the menuitem name in the search bar and you find it.
- Try to add two more sub-menu for
-
Add below code to create an action. This action will trigger when
Patients
menu is clicked. We have to set the action idpatient_action
in the menuitem. Andres_model
name should be the same as the model name.<record id="all_patient_action" model="ir.actions.act_window"> <field name="name">All Patients</field> <field name="type">ir.actions.act_window</field> <field name="res_model">kmhospital.patient</field> <field name="view_mode">tree,form,search,kanban</field> <field name="help" type="html"> <p class="o_view_nocontent_smiling_face"> Create Patients List </p> </field> </record>
- Try to add two more window actions for
Male Patients
andFemale patients
. - Check out the code for actions
When we click the menuitem showed in the previous picture it will show the
Action
that we have created already.And it will show all the information related to that action.
Restart the server and upgrade the module and it will show the module in the App menu. If we don't add the access rights that have done in previous page it will not show any menu and as well as our module.
- Try to add two more window actions for
-
After creating the menu it will look something like below.
-
Add below code to create tree view. The field name is the same as the name of models field that we have created earlier. It displays records in a tabular form.
<record id="patient_tree" model="ir.ui.view"> <field name="name">kmhospital.patient.tree</field> <field name="model">kmhospital.patient</field> <field name="arch" type="xml"> <tree> <field name="name"/> <field name="address"/> <field name="gender"/> <field name="phone"/> <field name="email"/> <field name="age"/> </tree> </field> </record>
It will show the list of records that have in the database. You can also create new patient information by using
Create
button and it will redirect to the form views.
-
Add below code to create form view. It will show a form to create and edit single records.
<record id="patient_form" model="ir.ui.view"> <field name="name">kmhospital.patient.form</field> <field name="model">kmhospital.patient</field> <field name="arch" type="xml"> <form> <sheet> <group> <group> <field name="name"/> <field name="address"/> <field name="phone"/> </group> <group> <field name="gender"/> <field name="email"/> <field name="age"/> </group> </group> <notebook> <page string="Appointments"> </page> </notebook> </sheet> </form> </field> </record>
Here some fields are required such as
Patient Name, Phone, Age
mentioned as deep color. Other fields are optional.
-
Add below code to create search view. It will lookup for patient information based on search criteria.
<record id="patient_search" model="ir.ui.view"> <field name="name">kmhospital.patient.search</field> <field name="model">kmhospital.patient</field> <field name="arch" type="xml"> <search string="Patients"> <field name="name"/> <field name="gender"/> <field name="phone"/> <field name="age"/> </search> </field> </record>
-
Add below code to create kanban view. It is an advanced view to display the records as cards.
<record id="patient_kanban" model="ir.ui.view"> <field name="name">kmhospital.patient.kanban</field> <field name="model">kmhospital.patient</field> <field name="arch" type="xml"> <kanban default_group_by="gender"> <field name="name"/> <field name="gender"/> <field name="phone"/> <field name="email"/> <templates> <t t-name="kanban-box"> <div class="oe_kanban_global_click"> <div class="oe_kanban_details"> <h1 class="o_kanban_record_title"><field name="name"/></h1> <ul> <li>Gender : <field name="gender"/></li> <li>Phone : <field name="phone"/></li> <li>Email : <field name="email"/></li> <li>Age : <field name="age"/></li> </ul> </div> </div> </t> </templates> </kanban> </field> </record>
It will create a kanban view based on the gender
male and female
.
-
Create
Doctor
,Department
,Appointments
andMedicalTest
model, add tree, form and kanban views, create menuitem for each model and perform actions when the menu is clicked based on the picture below. -
Go through all the views from here if you face any problems.