I want to return data from python to javascript. I am calling function get_students_in_a_class
in my js file. In which I want all the data which I am returning from python code in Odoo 10
Python code
@api.model def get_students_in_a_class(self): _logger = logging.getLogger(__name__) # _logger.info('Class id' + repr(val.x_class_id) ) parents = self.env['parents'].search([('partner_id','=', self.env.user.partner_id.id)]) _logger.info('Parents ' + repr(parents)) sessions = [] classes = [] students = [] for parent in parents: students = self.env['op.student'].search([('parents_ids','=', parent.id)]) _logger.info('Students ' + repr(students)) for student in students: classes = self.env['x_classes'].search([('id','=', student.x_class_id.id)]) _logger.info('Classes ' + repr(classes)) for clas in classes: sessions = self.env['sessions'].search([('class_id','=',clas.id)]) _logger.info('Sessions ' + repr(sessions)) d = dict() d['Classes'] = classes d['Sessions'] = sessions d['Students'] = students _logger.info('Data-->> ' + repr(d)) return d
Js code
odoo.define('javascript_module.demo', function(require){ "use strict" var model = require('web.Model'); var studentModel = new model('op.student'); var data = studentModel.call('get_students_in_a_class') console.log('data--->>>>>>>', JSON.stringify(data)); })
But it is showing error
Server application error {"message":"Odoo Server Error","code":200,"data":{"debug":"Traceback (most r recent call last):\n File \"E:\\Oddo\\Odoo 10.0\\server\\odoo\\http.py\", line 640, in _handle_exception\n File \"E:\\Oddo\\Odoo 10.0\\server\\odoo\\http.py\", line 691, in dispatch\n File \"E:\\Oddo\\Odoo 10.0\\server\\odoo\\http.py\", line 629, in _json_response\n File \"json\\__init__.pyc\", line 244, in dumps\n File \"json\\encoder.pyc\", line 207, in encode\n File \"json\\encoder.pyc\", line 270, in iterencode\n File \"json\\encoder.pyc\", line 184, in default\nTypeError: op.student(113, 115) is not JSON serializable\n","exception_type":"internal_error","message":"op.student(113, 115) is not JSON serializable","name":"exceptions.TypeError","arguments": ["op.student(113, 115) is not JSON serializable"]}}