Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Xml operations in odoo


Published on

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.

Published in: Business
  • Login to see the comments

  • Be the first to like this

Xml operations in odoo

  1. 1. XML Operations in Odoo
  2. 2. INTRODUCTION 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 user interface. Creating normal views from xml is explained in our previous blog :
  3. 3.  Here I would like to share some of the cool features you can use while working with Odoo XML.
  4. 4.  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.  A python parsel file for an XML is only required when we need complex calculation for the reports. <span t- field="request.env[''].search([],limit=1).a_field _name"/>
  5. 5.  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 request.session.uid Current databses using request.session.db Usage : <t t-esc="request.session.uid"/> <t t-esc="request.session.db"/>
  6. 6.  Accessing current user record  Any column in user table can be obtained by just using ‘user.column(field_name)’ from XML files. For example, ‘’ will give you the name of the user, ‘user.groups_id’ will give all the current users in the group.  Usage : <field name="domain_force" > ['|', ('public', '=', 'groups'), ('group_public_id', 'in', [ for g in user.groups_id])] </field> <strong t-field="" />
  7. 7.  Widgets Widgets can be used to make Odoo interface more user-friendly. We can change the appearance of a fie 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 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.
  8. 8.  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.
  9. 9. Refer this link for more:
  10. 10. Thank You ! Cybrosys Technologies Pvt. Ltd. Neospace, Kinfra Techno Park, Kakkancherry, Calicut University P.O. Calicut Kerala, India - 673635. Cybrosys Ltd 15, ST Antonys Road, Forest Gate, London England, E79QA. Cybrosys Technologies Pvt. Ltd. 1st Floor, Thapasya Building, Infopark, Kakkanad, Kochi, Kerala, India-682030.