This question has been flagged
3 Replies
9248 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!

Avatar
Discard

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

Best Answer

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

Avatar
Discard
Best Answer

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....

Avatar
Discard