Short-Circuit Operators and OpenERP reporting

Introduction

 

The logical operators in python (‘and’ and ‘or’) can be used extensively to sequentially evaluate a statement irrespective of the datatype of each element in the statement. They are called short circuit operators in python. Here we have brief description of how can we use them while programming with python. It is found to be very useful when we try to manipulate data in reports where in we can significantly change the data printed without editing the python code serving the report.

 

Howto

 

Let’s consider a statement involving three elements A, B and C. Now we can use define a statement like

 

>>flag=A and B or C

 

now if A is True* and B is False ,then the value assigned to flag will be that Contained in C. Python takes the values irrespective of the type of value stored in to the variable flag. If both A and B are True then definitely the value assigned will be same as that in B irrespective of the data type.

 

Data type

Truth Value

False Value

String

Any string value containing charactors

Integer

Any number except 0

0

Boolean

TRUE

FALSE

List

List with elements

Empty list

Dictionary

Dictionary with elements

Empty Dictionary

Tuple

Tuple with elements

Empty Tuple

Object

Any Class Object

None type

Instance

Any calss instance

None type

 

Table 1. True and False values for different data types

 

 

 

OpenERP reporting

 

The most common and easier way of reporting in OpenERP is sxw/rml reporting where the sxw file serves as a template for the report. Modifying the sxw template in rml reporting can make significant changes in the report without much modifications in the parser which converts the rml file to pdf.

 

We can use tags in sxw file comprising of several python operators and inbuilt functions. It could be really useful while creating reports. There is however lots of flexibility offered in development of parsers that we can achieve our needs in different ways.

 

You can use python relation operators ‘==’, ‘<‘,'<‘, and our short-circuit operators and lots more. We can create conditional structures using the above mentioned operators and produce required results with little thought and code. With the use of some existing OpenERP functions in reporting its never difficult to create reports with really dynamic contents. We can hide lines, tables and even entire report to blank or show data of your interest when the record in table gets updated.

Comments

vijayan: as a function pointer always points to a function stored in memory it is True always ".

Leave a Reply

Your email address will not be published. Required fields are marked *

  1. Suresh says:

    what about the truth value of function pointers in python?

    1. vijayan says:

      as a function pointer always points to a function stored in memory it is True always

© 2020 Zesty Beanz Pvt Ltd All Rights Reserved.