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?
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)
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
|Asked: 9/1/15, 12:29 PM|
|Seen: 702 times|
|Last updated: 9/3/15, 8:51 PM|