跳至内容
菜单
此问题已终结
1 回复
9196 查看

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
3月 15
3376
0
3月 15
4063
1
3月 15
4194
1
3月 15
6823
1
3月 15
8308