India

ZestyBeanz Technologies Pvt Ltd 4th Floor, Nila, Technopark Thiruvananthapuram,
India – 695581
Phone: +91 471 4063254
Fax : +91 471 2700171

   .

ZestyBeanz Technologies Pvt Ltd
61/3236, Manikkath Cross Road
Ravipuram, Kochi, India - 682016
Phone: +91 484 4063254

  UAE

Zesty Labs
Office # 2003, Millennium Plaza Building
Sheikh Zayed Rd, Dubai, UAE
Phone: +971 4333 2222​
Mobile: +971-52-7553466

  Germany​

ZestyBeanz Technologies GmbH
Reuterstraße 1
90408 Nürnberg
Fon: +49 911 4801 444
Fax: +49 911 4801 445

Short-Circuit Operators and OpenERP reporting

Contact Form


vijayan's picture

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.

Suresh's picture

what about the truth value of

what about the truth value of function pointers in python?

vijayan's picture

as a function pointer always

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