Reputation: 11
this is really good explanation about new API.
Also, I have question regarding computed one2many field. Consider this as example
Class parent has computed one2many field to Class child. I want that the one2many field is automatically filled with some random value.
So, I give my fields compute. Also make a method with @api.depends("some_field").
To insert a value to one2many field from the methods, i use childfield += self.env['class_child'].new({'key':value}).
At parent creation, it works fine, the one2many field is updated everytime the depended field is changed. The problem is at parent edit, when I tried to change the depends value, it got error :
TypeError: is not JSON serializable
I don't understand what wrong with my concept, am I wrong? or do i need to use another method when editing the parent class.
Thx
Upvotes: 0
Views: 1252
Reputation: 2314
Try this type of code:
self.env['class_child'].create({
'key': [(0, 0, {'field_name1': 'field Value', 'field_name2': 'field value'})]
For a one2many field, a lits of tuples is expected.
Here is the list of tuple that are accepted, with the corresponding semantics:
(0, 0, { values }) #link to a new record that needs to be created with the given values dictionary
(1, ID, { values }) #update the linked record with id = ID (write values on it)
(2, ID) #remove and delete the linked record with id = ID (calls unlink on ID, that will delete the object completely, and the link to it as well)
Example:
[(0, 0, {'field_name':field_value_record1, ...}), (0, 0, {'field_name':field_value_record2, ...})]
Upvotes: 0