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.

0

How to get the id of a new record

By
Simon Lee
on 11/8/16, 1:00 AM 180 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.

2

Nilmar Shereef

--Nilmar Shereef--
811
| 4 3 7
Calicut, India
--Nilmar Shereef--

Python Developer. Android Developer. .Net Developer

Nilmar Shereef
On 11/8/16, 1:53 AM

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

1
Sarga
On 11/8/16, 2:01 AM

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

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)

Stats

Asked: 11/8/16, 1:00 AM
Seen: 180 times
Last updated: 11/10/16, 10:52 AM