Odoo is the world's easiest all-in-one management software. It includes hundreds of business apps:
CRM | e-Commerce | Accounting | Inventory | PoS | Project management | MRP | etc.
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:
self.pool.get('ir.model.data').get_object_reference(cr, uid, 'module_name', 'external_id')
# do whatever
About This Community
This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.Register
Odoo Training Center
Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.Test it now
|Asked: 3/11/15, 11:37 AM|
|Seen: 1436 times|
|Last updated: 3/16/15, 8:10 AM|