Skip to Content
Меню
Вам необхідно зареєструватися, щоб взаємодіяти зі спільнотою.
Це запитання позначене
3 Відповіді
27709 Переглядів

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 can now do self.env.ref('external.identifier') 

Аватар
Відмінити
Найкраща відповідь

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) 


Аватар
Відмінити

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

Найкраща відповідь

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



Аватар
Відмінити
Related Posts Відповіді Переглядів Дія
2
січ. 17
6240
2
лип. 17
15644
2
лист. 15
4405
0
бер. 25
1414
0
січ. 25
3493