Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
3 ตอบกลับ
27724 มุมมอง

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
6241
How to filter by external id in domain? แก้ไขแล้ว
2
ก.ค. 17
15650
2
พ.ย. 15
4408
0
มี.ค. 25
1414
0
ม.ค. 25
3493