콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
1 회신
9155 화면

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
3364
0
3월 15
4041
1
3월 15
4152
1
3월 15
6786
1
3월 15
8260