Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
3 Odpowiedzi
27646 Widoki

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?

Awatar
Odrzuć
Najlepsza odpowiedź

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

Awatar
Odrzuć
Najlepsza odpowiedź

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) 


Awatar
Odrzuć

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

Najlepsza odpowiedź

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



Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
2
sty 17
6202
2
lip 17
15596
2
lis 15
4317
0
mar 25
1336
0
sty 25
3427