class HmsPrescription(models.Model):
_inherit = "prescription.order"
def get_history_patient(self):
cr = self.env.cr
filter = " "
if self.patient_id:
filter += "po.patient_id = " + str(self.id)
if self.prescription_date:
filter += "po.prescription_date = " + str(self.prescription_date)
sql = ("""
SELECT
ha.name,
po.prescription_date,
rp.birthday,
DATE_PART('year', AGE(po.prescription_date, rp.birthday)) AS age_years,
DATE_PART('month', AGE(po.prescription_date, rp.birthday)) AS age_months,
po.keluhan,
po.hasil_pemeriksaan,
po.tindakan_pengobatan
FROM prescription_order po
inner join hms_appointment ha on po.appointment_id = ha.id
INNER JOIN res_partner rp ON po.patient_id = rp.id
INNER JOIN hms_patient hp ON po.patient_id = hp.id
WHERE """ + filter + """;
""")
cr.execute(sql)
data = cr.dictfetchall()
self.env['prescription.order.history'].create(data)
this my query and this bottom code is xpath to view a new tab with a table /tree