Odoo Help


On_change with self.pool.get and browse

Tai Le Thanh
on 6/1/17, 4:43 AM 880 views

 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">
<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"/>

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


Jusab Sida (jsi)

--Jusab Sida (jsi)--
| 2 2 5
Gandhinagar, India
--Jusab Sida (jsi)--

Jusab Sida (jsi)
On 6/1/17, 7:08 AM

Hello  Tai Le Thanh,

In your on_change "onchange_sinhvien_lop" just change vals.lop to vals.lop.id

return {'value': {'lop': vals.lop.id}}


thank you. This problem waste my whole evening

Tai Le Thanh
on 6/1/17, 10:15 AM

About This Community

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


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 6/1/17, 4:43 AM
Seen: 880 times
Last updated: 6/1/17, 10:07 AM