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 )

2
  • Possible duplicate of How to get JSON data in an Odoo controller using type='json'? Commented Feb 28, 2018 at 9: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 Commented Feb 28, 2018 at 14:14

1 Answer 1

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 :)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.