Enable Dark Mode!
By: Amal

XML Operations in Odoo

Odoo views are dynamically created from XML codes. Data of Odoo are stored as objects and XML description is used to expose these objects to the user interface.

Creating normal views from XML is explained in our previous blog: Odoo views


Here I would like to share some of the cool features you can use while working with Odoo XML.


Searching for a model

Many people use a separate parser for XML reports just to get a value from another model. But we can call any model from XML itself using flowing code.


<span t-field="request.env['model.name'].search([],limit=1).a_field_name"/>


A python parsel file for an XML is only required when we need complex calculation for the reports.


Accessing Session

We can access the current session using ‘request.session’ from the XML file. Any value stored in session object can be obtained from it. For example, current user id can be obtained by


Current databses using  


<t t-esc="request.session.uid"/>
<t t-esc="request.session.db"/>



Accessing current user record


Any column in user table can be obtained by just using ‘user.column(field_name)’ from XML files. For example, ‘user.name’ will give you the name of the user, ‘user.groups_id’ will give all the current users in the group.



<field name="domain_force" > ['|', ('public', '=', 'groups'), ('group_public_id', 'in', [g.id for g in user.groups_id])] </field>
<strong t-field="user.name" />




Widgets can be used to make Odoo interface more user-friendly. We can change the appearance of a field without making changes in database columns.

<field name="field_name" widget="widget_name"/>


progressbar : widget=”progressbar” will create a progress bar for float or Integer fields.

float_time : widget=”float_time” is used to convert float field into time format, That is, 1.00 will be converted to 01:00.

url : widget=”url” create http link for the field.

email: widget=”email” will create a link to send the email.

Monetary: widget=”monetary” can be used with float field to show currency sign after the field.


t-esc and t-field

t-esc takes an expression, evaluate it and prints the content.


<p><t t-esc="value"/></p>


It can be also used to get values from an object:

<p><t t-esc="object.value"/></p>


But in case of a ‘field’ in a model it is better to use t-field.

<p><t t-esc="model.field_name"/></p>


Note:   If you use t-esc to render field, we won't be able to print fields which are not stored (like related fields, compute field without store = True etc.)
Note:   t-field can only be used when performing field access (a.b). It is able to automatically format based on the field type.

Odoo Training Package
Odoo Implementation Package

If you need any assistance in odoo, we are online, please chat with us.


Tomás Pascual

Great¡¡¡ Thank you very much,





Is it possible to get the XML ID of a record using the python code? I'm stuck with a situation where I need to get the XML id of a record. Is it possible to get Id from the table. It will be a great help for me as an Odoo Consultant, to provide me the solution. Thank you




Leave a comment



Cybrosys Technologies Pvt. Ltd.
Neospace, Kinfra Techno Park
Kakkancherry, Calicut
Kerala, India - 673635



Cybrosys Limited
Alpha House,
100 Borough High Street, London,
SE1 1LB, United Kingdom



Cybrosys Technologies Pvt. Ltd.
1st Floor, Thapasya Building,
Infopark, Kakkanad,
Kochi, India - 682030.



Cybrosys Techno Solutions
The Estate, 8th Floor,
Dickenson Road,
Bangalore, India - 560042

Send Us A Message