Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
3 Trả lời
27729 Lượt xem

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?

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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) 


Ảnh đại diện
Huỷ bỏ

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

Câu trả lời hay nhất

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



Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 1 17
6248
2
thg 7 17
15650
2
thg 11 15
4411
0
thg 3 25
1416
0
thg 1 25
3495