I use On_change, firstly, it work, but now it does not :(
My model (.py) :
class SinhvienList(osv.osv):
_name = "asinhvien.asinhvien"
_columns = {
'name': fields.char('Ten'),
'lop': fields.many2one('asinhvien.alop', 'Lop'),
}
class LopList(osv.osv):
_name = "asinhvien.alop"
_columns = {
'name': fields.char('Lop'),
'sinhvien' : fields.one2many('asinhvien.asinhvien','lop','Ten sinh vien' ),
}
class ChitietMon(osv.osv):
_name = "asinhvien.achitietmon"
_columns = {
'sinhvien' : fields.many2one('asinhvien.asinhvien','sinh vien'),
'lop' : fields.many2one('asinhvien.alop','Lop'),
}
def onchange_sinhvien_lop(self, cr, uid, ids, sinhvien, context=None):
if sinhvien:
vals = self.pool.get('asinhvien.asinhvien').browse(cr, uid, sinhvien, context=context)
return {'value': {'lop': vals.lop}}
return {'value': {}}
My view (.xml) :
<!-- Form View chi tiet mon -->
<record id="formview_sinhvien_chitietmon" model="ir.ui.view">
<field name="name">chitietmon form view</field>
<field name="model">asinhvien.achitietmon</field>
<field name="arch" type="xml">
<form>
<sheet>
<group string="Chi tiết môn học">
<field name="sinhvien" string="Tên sv" on_change="onchange_sinhvien_lop(sinhvien)"/>
<field name="lop" string="Lớp"/>
</group>
</sheet>
</form>
</field>
</record>
When I chose "sinhvien" of model "achitietmon", I want it fill "lop" automatically. But it occur error
Traceback (most recent call last): File "D:\workspace_odoo\projectGHN\src_GHN\openerp\http.py", line 492, in _handle_exception return super(JsonRequest, self)._handle_exception(exception) File "D:\workspace_odoo\projectGHN\src_GHN\openerp\http.py", line 512, in dispatch return self._json_response(result) File "D:\workspace_odoo\projectGHN\src_GHN\openerp\http.py", line 481, in _json_response body = simplejson.dumps(response) File "C:\Python27\lib\site-packages\simplejson\__init__.py", line 380, in dumps return _default_encoder.encode(obj) File "C:\Python27\lib\site-packages\simplejson\encoder.py", line 291, in encode chunks = self.iterencode(o, _one_shot=True) File "C:\Python27\lib\site-packages\simplejson\encoder.py", line 373, in iterencode return _iterencode(o, 0) File "C:\Python27\lib\site-packages\simplejson\encoder.py", line 268, in default raise TypeError(repr(o) + " is not JSON serializable") TypeError: browse_record(asinhvien.alop, 1) is not JSON serializable
Thanks for help