Перейти к содержимому
Меню
Чтобы взаимодействовать с сообществом, необходимо зарегистрироваться.
Этот вопрос был отмечен
3 Ответы
27212 Представления

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
5857
2
июл. 17
15182
2
нояб. 15
3918
0
мар. 25
828
0
янв. 25
2947