This question has been flagged
2 Replies
20964 Views

I am using odoo 9. When a new row is added in a tree view and before the "Save" button is clicked, is there any way I can get the id of this new row/record. self.id always returns False, it is of type NewId.

If this is not possible, is there anyway I can differential a row from another in the same tree view. For example, there are 2 new rows/records created before clicking the "Save" button. How can I identify row 1 from row 2 if both id is NewId???

Can someone share codes on how to do this.

Avatar
Discard
Best Answer

self.id is returning false because it is defined only after creation. An alternative idea to get the id before saving is find the last id of the models and calculate the next one.
For ex:
search_ids = self.pool.get('your.model').search(cr, uid, [])
last_id = search_ids and max(search_ids)



It gives the last id of that model, you will get the next id by simple addition by one. And I think you can't create all rows at a time. It is one by one process(In code).
I think it may help you

Avatar
Discard
Best Answer

Hi,

To get the Id of the new Record You can call Create function and call super the returning value will be the new id like


def Create(self,vals):

  res = Super.(Class_name,Self).create(vals)

#res is your new record id

#make your modification here  check the field valuesand comparisons here from vals and then return id

return res

Avatar
Discard