콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
3 답글
27252 화면

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 



아바타
취소
관련 게시물 답글 화면 활동
2
1월 17
5890
2
7월 17
15196
2
11월 15
3934
0
3월 25
849
0
1월 25
2976