-
If we choose a patient name while creating a new appointment, it will automatically fill the
Note
field and if we remove the patient it will be empty. This task is done usingonChange
function.@api.onchange('patient_id') def _change_appointment_note(self): if self.patient_id: if not self.note: self.note = "New appointment" else: self.note = ""
-
If we set
Note
as areadonly
field and save it will not store the data ofNote
. To save we have to useforce_save="1"
in the form view of theNote
field.<field name="note" readonly="1" force_save="1"/>
-
To compute the appointment of an individual doctor we have to find in the appointment table based on doctor id. Here
appointed_doctor_id
will come from the appointment model which is aMany2one
field.total_appointments = fields.Integer(string='No. of appointments', compute='_compute_appointments') # compute appointments of individual doctor def _compute_appointments(self): for record in self: record.total_appointments = self.env['kmhospital.appointment'].search_count( [('appointed_doctor_id', '=', record.id)])
-
We have use a for loop in the computed field as
self
contains multiple values otherwise it will ariseSingleton Error
. -
In the view file we have to add the field of
total_appointments
inside thePatient List
tab.<group string="No. of Appointments:"> <h2> <field name="total_appointments"/> </h2> </group>
- Try to compute patients appointment like doctor.