Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

ODOO9: How to parse json field in qweb?

By
Drees Far
on 6/10/16, 4:28 AM 531 views

Hello everybody!!!

Can anyone help me know how to parse a json field in qweb report for odoo9.

Here is my json:

{"employee": [{"id":1,"name":"RIHENE,ABDELWWAHED","matricule":"123456789","worked_day":22,"leave_days":0,"abs_day":0,"worked_holiday":0,"over_25":0,"over_50":0,"over_75":0,"over_100":0,"heures_sup":0,"net_target":0,"wage":"2500.000","contract": {"wage":2500,"adjustment_prime":11399,"struct_id":4,"struct_code":"MENSUEL"},"net":0,"cnss":0,"irpp":0,"brut":0,"base_cnss":0,"cnss_pat":0,"sal_imp":0,"at":0,"total_primes":0,"data_changed":false,"checked":false,"primes_details":false,"hours": [{"hours":0},{"hours":0},{"hours":0},{"hours":0},{"hours":0},{"hours":0},{"hours":0},{"hours":0},{"hours":0},{"hours":0},{"hours":0},{"hours":0},{"hours":0},{"hours":0},{"hours":0},{"hours":0},{"hours":0},{"hours":0},{"hours":0},{"hours":0},{"hours":0}, {"hours":0},{"hours":0},{"hours":0},{"hours":0},{"hours":0},{"hours":0},{"hours":0}],"struct":"MENSUEL"}]}

Thanks a lot in advance.

Best regards!

define a method in model and call it over report , and use two for each loop just like pattern printing

Prakash Sharma
on 6/10/16, 1:06 PM
0
Arsenty Karamurza
On 6/17/16, 7:52 AM

Don't forget you're inside a browser, so that there's JavaScript at your disposal )

0

Pawan

--Pawan--
1267
| 4 3 5
Hyderabad, India
--Pawan--


Pawan
On 6/13/16, 9:20 AM

Drees,

if you are having this in a variable and passed to xml from controller as:

result ={"employee": [{"id":1,"name":"RIHENE,ABDELWWAHED","matricule":"123456789","worked_day":22,"leave_days":0,"abs_day":0,

"worked_holiday":0,"over_25":0,"over_50":0,"over_75":0,"over_100":0,"heures_sup":0,"net_target":0,"wage":"2500.000",

"contract":"wage":2500,"adjustment_prime":11399,"struct_id":4,"struct_code":"MENSUEL"},"net":0,"cnss":0,"irpp":0,

"brut":0,"base_cnss":0,"cnss_pat":0,"sal_imp":0,"at":0,"total_primes":0,"data_changed":false,"checked":false,

"primes_details":false,

"hours": [{"hours":0},{"hours":0},{"hours":0},{"hours":0},{"hours":0},{"hours":0},{"hours":0},{"hours":0},{"hours":0},{"hours":0},{"hours":0},{"hours":0},{"hours":0},{"hours":0},{"hours":0},{"hours":0},{"hours":0},{"hours":0},{"hours":0},{"hours":0},{"hours":0}, {"hours":0},{"hours":0},{"hours":0},{"hours":0},{"hours":0},{"hours":0},{"hours":0}],"struct":"MENSUEL"}]}

then you can simply loop through it  and traverse over the data as:

<t t-foreach="employee" t-as="emp">

here 'emp' will singify each employee, and you can you normal python dictionary convention here:

emp['id'], will give you 1,

emp['name'] will give you 'RIHENE,ABDELWWAHED', and so on.......

and further again you can loop through each hours as,

<t t-foreach="emp['hours']" t-as="hour">

Then get each hour in loop........

Hope this will help you....

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 6/10/16, 4:28 AM
Seen: 531 times
Last updated: 6/17/16, 7:52 AM