0

i send data from extJS file to my odoo controller using Ext.Ajax.request like this :

Ext.Ajax.request({
    url : '/serviceAP/fun',
    headers :{
         'Content-Type' : 'application/json'
    },
    method : 'POST',
    jsonData : {"params":
          {"cat" : "cat4",
           "date" : "02/11/2015",
           "notes" : "this notes 4"}
         }
 })

and the controller is like this :

@http.route('/serviceAP/fun', type="json", auth='public', website=True)

def func_test(self,**args):
    http.request.env['sap.orders'].create({"cat": args['cat'], "order_date": args['date'],
                                          "notes": args['notes']})

    return None

it's works fine without any problem but now i want to add many params (cat5,cat6,...,catn) so i need to use a JS array i don't know how to handle it i tried many things but without result because this method is correct just for one json tuple i want to know how to handle it in the two side odoo (odoo controller/js return )

Amor.o
  • 491
  • 8
  • 21
  • Possible duplicate of [How to get JSON data in an Odoo controller using type='json'?](https://stackoverflow.com/questions/37111955/how-to-get-json-data-in-an-odoo-controller-using-type-json) – forvas Feb 28 '18 at 09:42
  • i saw it before it's not the same they talking about static data + one tuple json data and my question is about many tuples – Amor.o Feb 28 '18 at 14:14

1 Answers1

0

i find it to make a make it we should create a dictionair of dictionaries like this :

val = {}
val[0]={
 "cat": "cat4",
 "date": "02/11/2015",
 "notes": "this notes 4"
};
val[1]={
  "cat": "cat5",
  "date": "02/11/2015",
  "notes": "this notes 5"
};

after we should insert it to jsonData with the params key

jsonData : {"params":val}

and we use it directly in the controller :

i=0
while i < len(args):
   http.request.env['sap.orders'].create({"cat": args[str(i)]['cat'],  "order_date": args[str(i)]['date'],"notes": args[str(i)]['notes']})
   i = i+1

i hope it help ,thanks any way :)

Amor.o
  • 491
  • 8
  • 21