Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
3 Risposte
27612 Visualizzazioni

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
Abbandona
Risposta migliore

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

Avatar
Abbandona
Risposta migliore

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
Abbandona

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

Risposta migliore

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



Avatar
Abbandona
Post correlati Risposte Visualizzazioni Attività
2
gen 17
6172
2
lug 17
15573
2
nov 15
4296
0
mar 25
1292
0
gen 25
3398