تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
3 الردود
27271 أدوات العرض

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
يناير 17
5922
2
يوليو 17
15218
2
نوفمبر 15
3938
0
مارس 25
878
0
يناير 25
2995