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

Hello there,

My custom module controller make a string like « point_of_sale.index_2 ».

In Odoo, python, how to test if this external ID exists in my DB before to use it later in the code?

If I use this external ID in my python code and it doesn't exist, I get an error.

Thanks for your idea.

الصورة الرمزية
إهمال
أفضل إجابة

You could surround your code using that external_id with try/catch and do the appropriate thing in the catch clause if that id does not exist. If you need to do that check prior to the actual use of it you could use the method get_object_reference from ir_model_data and surround the code with try/except, like this:

try:

self.pool.get('ir.model.data').get_object_reference(cr, uid, 'module_name', 'external_id')

except ValueError:

# do whatever

الصورة الرمزية
إهمال
الكاتب

Very interesting. I test it soon and I come back.

Sorry,I meant except, not catch...

الكاتب

Thanks for your answer. Exactly what I needed.

المنشورات ذات الصلة الردود أدوات العرض النشاط
0
مارس 15
3578
0
مارس 15
4280
1
مارس 15
4364
1
مارس 15
7136
1
مارس 15
8632