hello i have code in my controller for return response like this
from odoo import http
from odoo.http import request
import json
import time
import datetime
from datetime import timedelta
from odoo.http import Controller,route,JsonRequest, Response
class list_code_tes(http.Controller):
@http.route('/api/code/tes', type='json', auth='user')
def list_code_tes(self, **rec):
if request.jsonrequest:
surgery = request.env['oeh.medical.surgery']
medical_record = rec['medicalrecord']
patient = request.env['oeh.medical.patient'].search([('identification_code','=', medical_record )], limit=1)
if not patient :
return ({
'code': 404,
'status': 'NOT FOUND',
'message': 'Patient not found.'
})
search_surgery = request.env['oeh.medical.surgery'].search([('patient','=', patient.id)],limit=1)
if not search_surgery:
return ({
'code': 404,
'status': 'NOT FOUND',
'message': 'Surgery Not Found.'
})
if search_surgery:
code = search_surgery.booking_code
date= search_surgery.date
name = search_surgery.unit_id.name
a = {
"bookingcode": code,
"surgerydate": date,
"poli": name,
"lastupdate": search_surgery.write_date,
}
return a
when using this code the return response will be like this:
"list" :[{
},
}
see this link :
https://stackoverflow.com/questions/2733813/iterating-through-a-json-object