Friday, 30.July LAT | ENG
Extra Functions PDF E-mail

There are set of embedded functions defined for user convenience. These represent generic functionality that is commonly used for creating reports. Listing of these functions is not to be considered as complete, we may introduce more functions over time. Do not hesitate to ask, if you want some function to appear among them. All requests will be treated as a wish-list, and if the requested function will appear as commonly required item we will gladly include it in the embedded function list. You may place your motivated request on launchpad project bugs/blueprints sections. You can use our dedicated forum, if you are not familiar with launchpad. Reports with attached source code will receive somehow better attention, so may be implemented more sooner.

You may vote for functionality by donating funds to this project and naming the functionality you would like to be implemented.

For better reference we decided to split listing of functions by domains.

Language related functions

SetLang

Frame3

Where:

language – language code;

Description:

This function changes default language used on template. It may affect other functions if specific language for them has not been set. Default language is effecive till the end of the report or next occurrence of setLang. You may want to use setLang function, to override default language used, for example, when you print invoice for the customer.

Example:

Frame4

In this code snippet we take language from the partner of particular invoice or default to English if no language has been set.

gettext

Frame5

Where:

text_to_translate – text to be translated;

Description:

Similar to gettext function, is being used to create multi language reports. This function has alias - an underscore.

Example:

Frame8

currency_to_text

Frame9

Where:

amount – sum of money to express in words;

currency – code of the currency. This is optional parameter. If not set, defaults to a currency of the company;

language – language code. This is optional parameter. If not set, defaults to the language of the report.

Description:

Provides functionality for expressing sum of money in words, which is commonly required on reports. Currently supports three languages – English (“en_US”), Latvian (“lv_LV”) and Russian (“ru_RU”). Currently function is able to work with three currencies – EUR, USD and LVL. Boundaries of amount of currency - 0 to 999999999999.99.

Example:

Frame7

getLang

Frame6

Description:

Returns current default language for template.

Mathematical functions

sum

Frame12

Where:

list_of_objects – list of objects that have field to sum;

field_name – name of the numeric field to sum, expressed as string;

Description:

Returns sum of named field from all objects in a list.

sumif

Frame10

Where:

list_of_objects – list of objects that have field to sum;

field_name – name of the numeric field to sum, expressed as string;

condition – condition on which objects should be selected, expressed as string;

Description:

Returns sum of named field from conditionally selected objects in a list.

Statistical functions

average

Frame11

Where:

list_of_objects – list of objects that have field;

field_name – name of the numeric field, expressed as string;

Description:

Returns the average (arithmetic mean) of fields from all objects in a list.

count

Frame13

Where:

list_of_objects – list of objects to count;

Description:

Returns total count of objects in a list.

count_blank

Frame14

Where:

list_of_objects – list of objects that have field;

field_name – name of the field to check for emptiness;

Description:

Returns total count of objects in a list, where named field is empty.

countif

Frame15

Where:

list_of_objects – list of objects that have field;

condition – condition on which objects should be selected, expressed as string;

Description:

Returns count of objects from a list, where fields meet condition.

large

Frame16

Where:

list_of_objects – list of objects that have field;

field_name – name of the numeric field to evaluate, expressed as string;

k – which value to return;

Description:

Returns k-th largest numeric value in a list of objects.

max

Frame17

Where:

list_of_objects – list of objects that have field;

field_name – name of the numeric field to evaluate, expressed as string;

Description:

Returns largest numeric value in a list of objects.

min

Frame18

Where:

list_of_objects – list of objects that have field;

field_name – name of the numeric field to evaluate, expressed as string;

Description:

Returns smallest numeric value in a list of objects.

small

Frame19

Where:

list_of_objects – list of objects that have field;

field_name – name of the numeric field to evaluate, expressed as string;

k – which value to return;

Description:

Returns k-th smallest numeric value in a list of objects.

Time related functions

dec_to_time

Frame20

Where:

time_amount – amount of time in numeric representation;

hour_fmt – format for hours, as string;

min_fmt – format for minutes, as string;

Description:

Converts time, supplied in numeric representation, to time in hour:min string representation. For example, “1.5” can be expressed as “1 h 30 min” or “1:30”.

Example:

Frame21

This example will return string - “7 h 15 min”.

Barcode related functions

Barcode

Frame29

Where:

Description:

Helper functions

asarray

Frame23

Where:

list_of_objects – list of OpenObject objects;

field_name – name of the field which should be returned as list;

Description:

Returns named field from all objects as a list.

asimage

Frame24

Where:

image – image content;

rotate – rotation aspect in degrees;

Description:

Returns binary field as image. This function is required to place image from OpenObject binary field or attachment to a template.

Example:

Frame35

Expression in this example takes image from attachment of first object and places it on a document.

debugit

Frame25

Where:

object – object which value you want to print to console.

Description:

Helps debugging templates. Run the server from command line and call 'debugit' from the template to inspect variables.

get_attachments

Frame26

Where:

object – OpenObject object from which attachment(s) should be extracted.

index - ;

name - ;

Description:

Returns attachment(s) from an object. When no index or name is

get_label

Frame27

Where:

object – OpenObject object which has named field.

field_name – name of the field, as string, which label to retrieve.

Description:

Returns human readable name for the field, which is usually displayed on forms or tree views as a label for widget.

Current default language is effective on output. Please see setLang() function.

Example:

Frame31

For report on partners, this will return “Total Payable”.

get_name

Frame33

Where:

object – OpenObject object which string representation to be returned.

Description:

Returns string representation for object as it would appear on form in many2one relation. This output from OpenObject name_get function.

Current default language is effective on output. Please see setLang() function.

get_selection_item

Frame30

Where:

object – OpenObject object which has named selection field.

field_name – name of the selection type field, as string.

Description:

Returns human readable name which would be displayed on form for selection field item instead of it's code.

Current default language is effective on output. Please see setLang() function.

safe

Frame32

Where:

expression – expression to evaluate, as string.

object – object which provides data for expression.

Description:

Tries to safely evaluate expression. If an exception occurs, empty string will be returned. If expression evaluates without problems it's result will be returned.

 
Copyright © 2001 KN dati SIA, ALL RIGHTS RESERVED