Se rendre au contenu
Menu
Cette question a été signalée
3 Réponses
27313 Vues

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?

Avatar
Ignorer
Meilleure réponse

You can now do self.env.ref('external.identifier') 

Avatar
Ignorer
Meilleure réponse

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) 


Avatar
Ignorer

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

Meilleure réponse

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



Avatar
Ignorer
Publications associées Réponses Vues Activité
2
janv. 17
5969
2
juil. 17
15264
2
nov. 15
3982
0
mars 25
922
0
janv. 25
3041