Odoo Help


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.


Populate Many2One field on change of another field on v8?

on 4/6/15, 11:47 PM 1,161 views


My code was working on v7 but when I move it to v8 I am getting an "is not JSON serializable" error

All I want to do is populate a Many2One field when another field in the view changes.

Here is the code which is giving me the error:

 amenity = fields.Many2one('sim.amenities','Payments Cols',required=True,ondelete='cascade')

def modify_amenities(self):
     res = {'value':{'amenities':False}}
     ret_ids = []
     if self.building:
          ret_ids = self.env['sim.amenities'].search([['cols', '=', self.building.id],])
ret_lines = []
              for amen_id in ret_ids:
ret_sub_list = []
ret_lines_dict = {}
amenity_obj = self.env['sim.amenities'].browse(amen_id.id)
print amenity_obj
               res = {'value':{'amenity':ret_lines}}
self.amenity = res

Any idea why I might be getting the error or in any case how can I populate the field amenity when the field building changes?

Any tip will be really appreciated! Thanks a lot

in v8. you can directly write value inside the current record using self. you don't need to assign dictionary.

Anil R. Kesariya
on 4/7/15, 5:39 AM


| 5 4 8
Kochi, India
ODOO technical and functional

        I like learning new thing, especially technical thing. I am a quick learner, I can learn technical things very fast. I have good logical skill,  I have immense interest in programming.

e-mail id : baijuks@hotmail.com

On 4/7/15, 1:06 AM


Here you are passing a list of values to a many2one field, that’s why you are getting JSON error.

You have to pass the 'id' of many2one record you want to set there. For Eg: (here amenity_id contains id of wanted record)

self.amenity = amenity_id 

Hope this helps.............

Hi! thanks! the thing is that I want the field amenity to contain a list of values, not just one value so the user can chose one of them.

on 4/7/15, 8:48 AM

I see now. I added the code you provided (self.amenity = amenity_id ) inside the foreach. The problem I am having now is that the Many2one field gets all the values, not only the ones I am passing. Is there any way I can delete all the other values? Thanks again!

on 4/7/15, 11:38 AM

i have the same issue,Yakito did you get answer ?

Abdallah Sahabn
on 6/5/15, 7:54 AM
Abdallah Sahabn
On 6/6/15, 10:01 AM

i have resolved the issue 

you can return the domain , hope this can help you 

return {'domain':{'amenity': [('id', 'in', ret_lines)]}} 

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

1 follower(s)


Asked: 4/6/15, 11:47 PM
Seen: 1161 times
Last updated: 6/6/15, 10:01 AM