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.

1

One2many onchange is not working ODOO 9 TypeError: <openerp.models.NewId object at 0x7f1d3a6d6610> is not JSON serializable

By
sridhar
on 11/4/15, 4:06 AM 2,130 views

Can't pass the value to one2many table, this is my code, previous version ODOO 8 this functionality is working but in ODOO 9 it is not working, in where I did a mistake kindly notify that.

My Error message is 
Odoo Server Error
Traceback (most recent call last):
File "/home/sridharan/odoo-20151013/openerp/http.py", line 599, in _handle_exception
return super(JsonRequest, self)._handle_exception(exception)
File "/home/sridharan/odoo-20151013/openerp/http.py", line 650, in dispatch
return self._json_response(result)
File "/home/sridharan/odoo-20151013/openerp/http.py", line 588, in _json_response
body = json.dumps(response)
File "/usr/lib/python2.7/json/__init__.py", line 243, in dumps
return _default_encoder.encode(obj)
File "/usr/lib/python2.7/json/encoder.py", line 207, in encode
chunks = self.iterencode(o, _one_shot=True)
File "/usr/lib/python2.7/json/encoder.py", line 270, in iterencode
return _iterencode(o, 0)
File "/usr/lib/python2.7/json/encoder.py", line 184, in default
raise TypeError(repr(o) + " is not JSON serializable")
TypeError: <openerp.models.NewId object at 0x7f1d3a6d6610> is not JSON serializable
Code is here
def onchange_duplicate_supplier(self, cr, uid, ids, name, context=None):
if name == False:
return True
if name != False:
ls = []
supplier_obj = self.pool.get('sample.supplier')
bo_id = supplier_obj.search(cr, uid, [('name','ilike',name)])
for line in supplier_obj.browse(cr, uid, bo_id):
ls.append((0,0,{
'name' : line.name
}))
return {'value': {'supplier_merge_ids':ls}}        

We getting same issue, one2many on onchange not working. upgrade is hell, working fine for us in older version but 9.0 had issues.

Zahin
on 1/25/16, 5:23 AM
0
sridhar
On 1/25/16, 6:58 AM

@api.multi

def onchange(self, values, field_name, field_onchange):

try:

match = onchange_v7.match(field_onchange[field_name])

if match:

method, params = match.groups()

# evaluate params -> tuple

global_vars = {'context': self._context, 'uid': self._uid}

if self._context.get('field_parent'):

class RawRecord(object):

def __init__(self, record):

self._record = record

def __getattr__(self, name):

field = self._record._fields[name]

value = self._record[name]

return field.convert_to_onchange(value)

record = self[self._context['field_parent']]

global_vars['parent'] = RawRecord(record)

params = eval("[%s]" % params, global_vars, values)

# call onchange method with context when possible

args = (self._cr, self._uid, self._ids) + tuple(params)

try:

method_res = getattr(self._model, method)(*args, context=self._context)

except TypeError:

method_res = getattr(self._model, method)(*args)

return method_res

super(model_name,self).onchange(values, field_name, field_onchange)

except TypeError:

return True

pass


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

2 follower(s)

Stats

Asked: 11/4/15, 4:06 AM
Seen: 2130 times
Last updated: 5/27/16, 1:40 AM