Let’s say we have the following record in our data file:

<record model="res.partners" id="partner_rec_to_find"> ... </record>

How can we retrieve the xml-id with code-behind?

we just have to call odoo.env.ref(external_id).

For exemple:

my_partner = self.env.ref('res.partners.partner_rec_to_find')

You can get the reference of xml id using env.

product_id = self.env.ref('product.product_to_find').id

and below is the alternative way to get the record by xml id

ir_model_obj = self.pool['ir.model.data']
= ir_model_obj.get_object_reference(self._cr, self._uid, 'product', 'product_to_find')
= product_recs and product_recs[1] or False