Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
3754 Vizualizări

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:

"response": {
        "lastupdate""2020-11-27 13:12:23",
        "bookingcode""S/20112700005",
        "poli""test",
        "surgerydate""2020-11-27"
    } but i need the return the response like this

"response": {
    "list" :[{
        "lastupdate""2020-11-27 13:12:23",
        "bookingcode""S/20112700005",
        "poli""test",
        "surgerydate""2020-11-27"
    },
{
        "lastupdate""2020-11-27 13:12:23",
        "bookingcode""S/20112700006",
        "poli""test123",
        "surgerydate""2020-11-27"    
]}
}

can someone help me how to change the response? (*note : i use limit=1 in search surgery because i dont know how to make response looping like i want)
Imagine profil
Abandonează

see this link :

https://stackoverflow.com/questions/2733813/iterating-through-a-json-object

Related Posts Răspunsuri Vizualizări Activitate
1
iul. 25
8594
0
ian. 21
13263
2
dec. 19
9678
1
apr. 17
12830
2
mai 15
7186