Odoo Help


How can I retrieve a record with its external id in code-behind

Justin Lessard
on 9/1/15, 12:29 PM 1,897 views

How can I find a record in database using its External Id?

Let's say I have the following record in my data file:

<record model="product.product" id="product_to_find"> ... </record> 

How can I retrieve it in code-behind?

Axel Mendoza
On 9/1/15, 4:53 PM

You retrieve it with a code like:

res_model, res_id = self.pool.get('ir.model.data').get_object_reference(cr, uid,'module','product_to_find')
product = self.pool.get(res_model).browse(cr, uid, res_id)

or using the new api

res_model, res_id = self.env['ir.model.data'].get_object_reference('module','product_to_find')
product = self.env[res_model].browse(res_id) 

To complete this answeer... get_object(...) return immediately the record in new API. The same in old API is : xmlid_to_object(...)

Jérémy Kersten (jke)
on 9/1/15, 5:27 PM


Axel Mendoza
on 9/1/15, 5:27 PM

Try to search it the same way searching the view id of a certain view 

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.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

2 follower(s)


Asked: 9/1/15, 12:29 PM
Seen: 1897 times
Last updated: 10/6/17, 6:42 AM