How to get database id from XML id

osv.osv provides a get_xml_id method for finding the XML identifier for the provided database identifier. What is the best way to do the opposite?

Knowing the XML identifier (it was defined in the data load file), how can I get the corresponding database identifier so that I can refer to it in the Python tour course?

+6
source share
2 answers

The ir_model_data object has a _get_id() method that does what you are looking for. You can use it in the res_users._get_admin_id() method :

 def _get_admin_id(self, cr): if self.__admin_ids.get(cr.dbname) is None: ir_model_data_obj = self.pool.get('ir.model.data') mdid = ir_model_data_obj._get_id(cr, 1, 'base', 'user_root') self.__admin_ids[cr.dbname] = ir_model_data_obj.read(cr, 1, [mdid], ['res_id'])[0]['res_id'] return self.__admin_ids[cr.dbname] 
+7
source

The ir.model.data model also has a get_object() method that returns the get_object() viewed record with the model name and xml_id.

So another solution could be:

  m = self.pool.get('ir.model.data') id = m.get_object(cr, uid, 'base', 'user_root').id 
+10
source

Source: https://habr.com/ru/post/904658/


All Articles