Retrieving Data

When it is more or less clear, how to place a container, you would want to know, how to retrieve real data from objects. As it is always better to learn by example, we will use Partners model as referenced data in examples. This data model is almost always present in any database, and is populated with data, when demo setup has been created.

When creating report on any model, it is common to use default parser. Default parser provides several predefined variables:

  • objects – hold the data you create report on. It is a list of objects, so if you want to reference on all of the data selected, you have to place a loop on this variable;
  • o – if you know that only one object is selected, you may use this variable directly, without creating a loop;
  • data – data that comes from the wizard;
  • user – user which requests the report;
  • time – standard Python library for time manipulations;
  • company - ;
  • user - ;
  • report_xml - ;
  • user_lang - ;
  • logo - ;

For example, if you want to report name of the first partner you have selected, code would look:

<objects[0].name>

Here we reference predefined variable objects, use list index “0” (for information reference Python documentation), then take data from name field. Those who are not familiar with OpenObject ORM, for more information, take a look at “Administration/Customization/Database Structure/Objects” OpenERP objects and their relation listing.

You can reach any data from OpenObject ORM, just drill down step by step to the data you require.

For example, let's place currency of the company. The directive would look:

<user.company_id.currency_id.code>

Here we reference predefined variable user, take field company_id, which holds reference to the company, then currency_id for the default currency. Finally take field code which is of type text, so it can be directly reported on the template.

Copyright © 2001 Alistek Ltd., ALL RIGHTS RESERVED