Odoo Help


This community 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.


How to reference record in database by is XML id?

on 9/3/15, 6:02 AM 2,924 views


I'm writing a parser for an Aeroo report for expenses.

In the py code I need to make some reference to specific product categories, created within the same module via XML serialization, eg.:

<record id="park" model="product.category"> <field name="parent_id" ref="hr_expense.cat_expense"/> <field name="name">Parking tickets</field> </record>

How can I reference in the py code the category having the id "park"?


Serpent Consulting Services Pvt. Ltd.

--Serpent Consulting Services Pvt. Ltd.--
| 6 6 8
Gandhinagar, India
--Serpent Consulting Services Pvt. Ltd.--

Serpent Consulting Services Pvt. Ltd. Your Odoo/OpenERP Solution, just an email away!

Serpent Consulting Services Pvt. Ltd.
On 9/3/15, 6:17 AM

Hello Raffaele,

All the xml records are stored in "ir.model.data" object. There is a method called "get_object_reference" which gives you the database ID from xml ID.

In this method you have to pass module name where xml record is created and xml ID of the record.



self.pool.get('ir.model.data').get_object_reference(cr, uid, 'module_name', 'xml_id_of_record')[1]


record_id = self.env.ref('module_name.xml_id_of_record').id
On 9/3/15, 9:24 AM


Solution of Serpent Consulting Services Pvt. Ltd. is from V7 and works in V8 as well.
for anyone who is needing it in V8 you can do it in a simpler way with new api

record_id = self.env.ref('module_name.xml_id_of_record').id 

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)


Asked: 9/3/15, 6:02 AM
Seen: 2924 times
Last updated: 9/7/15, 1:18 AM