Reputation:
How can i check that demo data is loaded or not in a database from python code.I know other ways to check , but i need to check it by code.
Upvotes: 3
Views: 333
Reputation: 14751
I think the easiest way to do is by checking if the XML-ID is loaded :
# checking if the demo user record exist in database
# don't forget the put the full qualifying XML-ID (addon_name.xml_id)
if not self.env.ref('base.user_demo', raise_if_not_found=False):
# demo user is not loaded in database
Odoo maps the XML-ID with the real ID in database using this model ir.model.data
if the record is loaded ref
will return the record from the database else it will raise an exception
or return None
based on the second argument raise_if_not_found
by default it's True
Upvotes: 5