Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
3 Odpovědi
27230 Zobrazení

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
Zrušit
Nejlepší odpověď

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

Avatar
Zrušit
Nejlepší odpověď

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
Zrušit

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

Nejlepší odpověď

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



Avatar
Zrušit
Related Posts Odpovědi Zobrazení Aktivita
2
led 17
5865
2
čvc 17
15187
2
lis 15
3929
0
bře 25
832
0
led 25
2955