Odoo is the world's easiest all-in-one management software. It includes hundreds of business apps:
CRM | e-Commerce | Accounting | Inventory | PoS | Project management | MRP | etc.
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.
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.
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
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
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
About This Community
This platform 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.Register
Odoo Training Center
Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.Test it now
|Asked: 11/8/16, 1:00 AM|
|Seen: 591 times|
|Last updated: 11/10/16, 10:52 AM|