
Posts by Shankar Balachandran:
- When you have a native jdbc connectivity code and you do not want to change that, but bring that under a DAL code.
- When you have attached a file to a record and want to process that using the actual file path.
- When you need your current database name.
- When you need your current database parameters like URL, username,password, etc
- When you want the current context name using which the instance will be accessed.
- Import the package org.openbravo.base.session.OBPropertiesProvider.
- Use the getProperty(property name) method on the OBPropertiesProvider
- Pass the name of the parameter whose value you require to the getProperty() method.
Openbravo WebPOS Demo
March 28th, 2013Filed under: Openbravo
Comments Off
Enable/Disable options in Openbravo using Preferences
January 28th, 2013In Openbravo ERP, preferences are a cool and effective way to manage restrictions and apply certain additional actions at various levels like Client, Organization, Role and even at the window level. For more information on using preferences, refer http://wiki.openbravo.com/wiki/Preference
One such preference was enabling/disabling toolbar options like Delete, Attach, Export. From Openbravo 3.0 MP17 you can enable or disable these options for a particular window or a particular user and even for a particular role. Lets see few scenarios where this could come handy.
Note that all these options are enabled by default and using preferences you will only be able to disable them.
Usecase 1 : Restrict Deletion of Records
John is a new intern and maintaining User Information. Though he should be allowed access to 'user' information window, he should not be allowed to delete Users. This can be done by creating a preference as in the screenshot. Once this setting is saved, John will not be able to delete records from the User Window.
Usecase 2 : Restrict export data
John (again) has also access to the General ledger window. But since this is a critical data, you do not want him to be able to Export this information. Usually the export is done through the Export as Spreadsheet option provided at each window. To disable this you need to create a preference like the below screenshot.
Usecase 3: Restrict attachments option
David handles the goods receipt section. As soon as he receives a shipment, he uploads the scanned copy of the receipt to the Goods Receipt record. But you want all users with the role 'Sales' to be able to view the Goods Receipt window, but not be able to view the attachments. You can achieve this by creating a preference as follows
Hope these cases give a clear picture of the advantages of using these preferences.
One such preference was enabling/disabling toolbar options like Delete, Attach, Export. From Openbravo 3.0 MP17 you can enable or disable these options for a particular window or a particular user and even for a particular role. Lets see few scenarios where this could come handy.
Note that all these options are enabled by default and using preferences you will only be able to disable them.
Usecase 1 : Restrict Deletion of Records
John is a new intern and maintaining User Information. Though he should be allowed access to 'user' information window, he should not be allowed to delete Users. This can be done by creating a preference as in the screenshot. Once this setting is saved, John will not be able to delete records from the User Window.
Usecase 2 : Restrict export data
John (again) has also access to the General ledger window. But since this is a critical data, you do not want him to be able to Export this information. Usually the export is done through the Export as Spreadsheet option provided at each window. To disable this you need to create a preference like the below screenshot.
Usecase 3: Restrict attachments option
David handles the goods receipt section. As soon as he receives a shipment, he uploads the scanned copy of the receipt to the Goods Receipt record. But you want all users with the role 'Sales' to be able to view the Goods Receipt window, but not be able to view the attachments. You can achieve this by creating a preference as follows
Hope these cases give a clear picture of the advantages of using these preferences.
Comments Off
Tips to speed up Openbravo Development
January 8th, 2013Openbravo as framework is as powerful as Openbravo as an ERP. Development and Customization has been very much streamlined due to the MVC architecture and the modular approach. That is one reason there are so many modules/verticals available on top of Openbravo.
Here are few tips that helped me increase my productivity in Openbravo development. This is more like a compiled list from various articles that I used. Feel free to add more to it in the comments.
1. SQL Query Editor
A feature that is available for a long time, the SQL Query Editor available in System Administrator role can be used for quick selects across any table in Openbravo. This could save your time from switching back from your query tool to the Application. To open the query Editor, go to SQL Query in the System Adminstrator role.
2. HQL Query Editor
A more useful tool that is provided as a module by Openbravo is the HQL Query Tool. This query can be used to perform hql query across all the Entities present in Openbravo. One advanced feature is that you can select your desired Entity from a drop down and find all the attributes of the Entity. To install the same, login as System Administratior, go to Module Management Window and search for 'Openbravo HQL Query Tool'.
3. Auto Logon Manager
The most time consuming task for me while developing is to type the default username and password more than few hundred times per day (increases exponentially with my potential code blunders). A simple feature that would remove this hassle is to use the Authentication Manager in Openbravo. Just add the following lines under Authentication section in Openbravo.properties file in config folder (or anywhere in the file, better to put it in the right section) to login into the Application as Openbravo user without having to enter the user credentials.
authentication.class=org.openbravo.authentication.basic.AutologonAuthenticationManager
authentication.autologon.username=Openbravo
Source : http://planet.openbravo.com/?p=7012
4. Smartclient Development Module
The smartclient development module provides you with an uncompressed version of the SmartClient components, thereby assiting in deep debugging of the Client side smartclient code, and also can provides non-obfuscated code so that you can debug even the custom code. More on the this module here.
http://wiki.openbravo.com/wiki/Client_Side_Development_and_API#The_smartclient.dev_module.2C_smartclient_console_and_sources
5. Logging into multiple roles at the same time
More often than not we will be usually juggling between the client admin login and the System Administrator login. To save time from switching over one login to another, there are two ways.
1. Use incognito /private browsing mode. Using the incognito mode, one role opened in a session and another role opened in another session (separate windows).
2. A simpler way is to use Ip/domain name differentiation. For eg., if you are running Openbravo in your local instance then you can have two tabs opened, one with the URL http://locahost:8080/Openbravo and other with 127.0.0.1:8080/Openbravo and have two different roles in each tab.
6. Debugger in chrome developer tools
One technical tip while debugging client side code, if you are not sure what your code actually errors out, you can use the 'debugger;' keyword that will stop the execution of the script at that point. But just be careful to remove the keyword after debugging so that the Application does not do that for unintended circumstances.
Here are few tips that helped me increase my productivity in Openbravo development. This is more like a compiled list from various articles that I used. Feel free to add more to it in the comments.
1. SQL Query Editor
A feature that is available for a long time, the SQL Query Editor available in System Administrator role can be used for quick selects across any table in Openbravo. This could save your time from switching back from your query tool to the Application. To open the query Editor, go to SQL Query in the System Adminstrator role.
2. HQL Query Editor
A more useful tool that is provided as a module by Openbravo is the HQL Query Tool. This query can be used to perform hql query across all the Entities present in Openbravo. One advanced feature is that you can select your desired Entity from a drop down and find all the attributes of the Entity. To install the same, login as System Administratior, go to Module Management Window and search for 'Openbravo HQL Query Tool'.
3. Auto Logon Manager
The most time consuming task for me while developing is to type the default username and password more than few hundred times per day (increases exponentially with my potential code blunders). A simple feature that would remove this hassle is to use the Authentication Manager in Openbravo. Just add the following lines under Authentication section in Openbravo.properties file in config folder (or anywhere in the file, better to put it in the right section) to login into the Application as Openbravo user without having to enter the user credentials.
authentication.class=org.openbravo.authentication.basic.AutologonAuthenticationManager
authentication.autologon.username=Openbravo
Source : http://planet.openbravo.com/?p=7012
4. Smartclient Development Module
The smartclient development module provides you with an uncompressed version of the SmartClient components, thereby assiting in deep debugging of the Client side smartclient code, and also can provides non-obfuscated code so that you can debug even the custom code. More on the this module here.
http://wiki.openbravo.com/wiki/Client_Side_Development_and_API#The_smartclient.dev_module.2C_smartclient_console_and_sources
5. Logging into multiple roles at the same time
More often than not we will be usually juggling between the client admin login and the System Administrator login. To save time from switching over one login to another, there are two ways.
1. Use incognito /private browsing mode. Using the incognito mode, one role opened in a session and another role opened in another session (separate windows).
2. A simpler way is to use Ip/domain name differentiation. For eg., if you are running Openbravo in your local instance then you can have two tabs opened, one with the URL http://locahost:8080/Openbravo and other with 127.0.0.1:8080/Openbravo and have two different roles in each tab.
6. Debugger in chrome developer tools
One technical tip while debugging client side code, if you are not sure what your code actually errors out, you can use the 'debugger;' keyword that will stop the execution of the script at that point. But just be careful to remove the keyword after debugging so that the Application does not do that for unintended circumstances.
Comments Off
Sub reports in Openbravo
October 8th, 2012Report is one of the key USP for any ERP application. The more enhanced and flexible the reports are, more happy is the customer. In Openbravo, jasper reports provides us the flexibility to handle all this. iReport is one tool that can be used to create jasper reports. I have provided a simple example of how to add sub-report for an Openbravo Report using iReport.
Main Report:
Assume we have created a main report with the following query and layout.

Adding Sub Report:
The Sub Report can be created by adding the sub report icon as follows.
The sub-report can be added by drag and dropping the highlighted portion in the above screen shot. It will open the sub report wizard.
The sub report can be created in any one of the following three ways. Each way has different number of configuration steps.
1. A new sub report can be created using the wizard by using the "Create a new Report" Option. This will ask for all the options needed to create a new report including the report query. This will go through all the 7 steps.
The Sub Report expression can be any one of the following two options.
1. Through SUBREPORT_DIR Parameter
This will create a parameter SUBREPORT_DIR in Main Report. We have to point this parameter to the folder containing the sub report.
2. Through absolute path.
2. We can also call a already existing report as a sub report. This can be done by "Use an existing Report" option. We have to provide the path of the existing report. This will directly go to step 6 skipping the steps before that.
3. The last option will just create a blank sub report.
Adding Parameter:
In the Report Properties window, there is an option called parameter. This option enables us to add the parameter for that particular report.
Sub Report Query:
Note that you can see the parameter in the available parameters list in the above screen shot. We can also add the parameter through the "New Parameter" button in the above screen shot.
Importing Report in Openbravo:
For importing the report into openbravo, the jrxml files should be placed inside your module. For instance, if your module is XYZ with the Java Package com.fugoconsulting.XYZ, then the jrxml file should be inside the folder modules/com.fugoconsulting.XYZ/src/com/fugoconsulting/XYZ/erpReports/. Before importing the report into openbravo, we need to give the relative path for the sub-report and the images that we have added. This will make the report work in all systems irrespective of the path of the report. In order to give relative path, you need to add the following two parameters in main report.
1. BASE_DESIGN:
This parameter will be resolved at run time and will be pointing to your module folder(In our case modules/com.fugoconsulting.XYZ/src). The sub report expression must be modified as follows. This can be modified using the property "Sub report Expression".
2. BASE_WEB:
This parameter will be resolved to point the web folder at run time. This parameter is used to give the relative path for images. The sub report expression must be modified as follows.
Registering in Reports and Process:
Create menu and compile the application. The output will be,
For creating charts using iReport refer here.
Comments Off
Dissecting Openbravo 3.0 UI Architecture
April 25th, 2012Having been worked on Openbravo 3.0 UI for more than a year now (right from RC1) , Openbravo has leaped ahead of most contemporary ERP's in terms of UX design and usability. And a part of the credit has to go to the community too as they were actively involved in finalizing the UX and also involved enthusiastically in tested out the RC versions and providing their feedback.
In this post, I have tried to draw limelight on the basic UI components that are being used in Openbravo and their corresponding smartclient components. This is just to provide a very high level idea on how the entire architecture is coupled together. I have tried to use a single screen shot of Openbravo interface and tried to map the base components here.
The hierarchy can be visualized in simple terms as follows:
Exhaustive information on these components are provided in the Openbravo Wiki here.
Most of these components are defined and managed from individual files (or code) thereby making it really easy to extend or customize even the UI layer. As a simple trial I shifted the TopLayout to bottom to give it a windows (OS) like experience. Not being so acquainted with scripting languages, I was really surprised by the simplicity with which I could manage that (though finding that took me a bit longer).
I wanted to share what I found and liked about this code. I would like to be corrected in case I have mentioned any component incorrectly or mapped them in an inappropriate hierarchy. The end goal is to make sure we understand the architecture so that it can be appreciated better.
Happy Working !!!
In this post, I have tried to draw limelight on the basic UI components that are being used in Openbravo and their corresponding smartclient components. This is just to provide a very high level idea on how the entire architecture is coupled together. I have tried to use a single screen shot of Openbravo interface and tried to map the base components here.
The hierarchy can be visualized in simple terms as follows:
Exhaustive information on these components are provided in the Openbravo Wiki here.
Most of these components are defined and managed from individual files (or code) thereby making it really easy to extend or customize even the UI layer. As a simple trial I shifted the TopLayout to bottom to give it a windows (OS) like experience. Not being so acquainted with scripting languages, I was really surprised by the simplicity with which I could manage that (though finding that took me a bit longer).
I wanted to share what I found and liked about this code. I would like to be corrected in case I have mentioned any component incorrectly or mapped them in an inappropriate hierarchy. The end goal is to make sure we understand the architecture so that it can be appreciated better.
Happy Working !!!
Comments Off
Automating Attachments process in Openbravo and the Newton’s third law of Motion
October 22nd, 2011Newton at times gets it right. I love his third law of motion. It’s the Newton’s third law that inspired to do something about which I am posting now. I had to work on a Excel processing scenario where data in the form of excel was to be transmitted between Openbravo and another legacy System (I prefer to call .N** applications legacy systems). Filling the * is left to your imagination.
For data import, I first thought to create an import process like this, but then it was a day to day transaction, so thought it was not so efficient for auditing process. So I decided to use the Openbravo Attachments. So the user uploads an excels and saves the record and I process it accordingly. Part 1 complete. The next stage was creating a report for legacy system and providing it to the user. First I generated it in a particular drive and then users would access it. That was not proving to be good due to many access issues. Then I tried to create a File Dialog reference that would save the file in the location which user specifies. But then the question arises, what if the data is lost somewhere and an user tells he never downloaded it?
Then Newton came to my rescue. The attachments process in Openbravo has a cool feature that I decided to leverage. Not only can users attach files to a record, but they can also download files from an record. So in accordance to the Newton’s third law, if I could process an excel that user had uploaded, why can’t I create an excel and attach an record it to it and let the user download it? Having it operational was the only thing that occupied my mind for about an week.
How attachment works in Openbravo:
When you attach a file to a record, there is a folder created inside the attachment folder (the attachment folder is configured while setting up the instance as mentioned here). The name of the folder will be “tableid-recordid” , where tableid is the unique id of the corresponding table and recordid is the unique id of the record you are planning to attach.Then there is a record created in the C_File table with the File Name, Record Id, TableId. This is interpreted in the application and is presented to us in the application.
This is how my record will be (it’s in Classic UI).

Once the user clicks on the user clicks the Generate Process , a file is created, a folder with the recordid and tableid is created and an entry is made is in the C_File table. Easy. Done. We have attached the excel to the record. This is how the record looks now.

Now the user can just click the pointed button and download the corresponding excel file.
.
May be it will be useful in any of your interactions with legacy systems…:)
For data import, I first thought to create an import process like this, but then it was a day to day transaction, so thought it was not so efficient for auditing process. So I decided to use the Openbravo Attachments. So the user uploads an excels and saves the record and I process it accordingly. Part 1 complete. The next stage was creating a report for legacy system and providing it to the user. First I generated it in a particular drive and then users would access it. That was not proving to be good due to many access issues. Then I tried to create a File Dialog reference that would save the file in the location which user specifies. But then the question arises, what if the data is lost somewhere and an user tells he never downloaded it?
Then Newton came to my rescue. The attachments process in Openbravo has a cool feature that I decided to leverage. Not only can users attach files to a record, but they can also download files from an record. So in accordance to the Newton’s third law, if I could process an excel that user had uploaded, why can’t I create an excel and attach an record it to it and let the user download it? Having it operational was the only thing that occupied my mind for about an week.
How attachment works in Openbravo:
When you attach a file to a record, there is a folder created inside the attachment folder (the attachment folder is configured while setting up the instance as mentioned here). The name of the folder will be “tableid-recordid” , where tableid is the unique id of the corresponding table and recordid is the unique id of the record you are planning to attach.Then there is a record created in the C_File table with the File Name, Record Id, TableId. This is interpreted in the application and is presented to us in the application.
This is how my record will be (it’s in Classic UI).

Once the user clicks on the user clicks the Generate Process , a file is created, a folder with the recordid and tableid is created and an entry is made is in the C_File table. Easy. Done. We have attached the excel to the record. This is how the record looks now.

Now the user can just click the pointed button and download the corresponding excel file.
May be it will be useful in any of your interactions with legacy systems…:)
Comments Off
Retrieving Openbravo properties in DAL code
August 16th, 2011Openbravo.properties is the configuration page in which we specify the source folder, the database configuration and many other configuration parameters. For more information on Openbravo.properties configuration, refer here.
There will be many cases where we will need the values of the parameters configured in the Openbravo.properties. Few cases are.
There will be many cases where we will need the values of the parameters configured in the Openbravo.properties. Few cases are.
package com.fugoconsulting.XXX.erpCommon.ad_process;
import org.apache.log4j.*;
import org.openbravo.erpCommon.utility.OBError;
import org.openbravo.scheduling.ProcessBundle;
import org.openbravo.dal.service.OBQuery;
import org.openbravo.dal.service.OBDal;
import org.openbravo.dal.core.SessionHandler;
import org.openbravo.base.session.OBPropertiesProvider;
/**Happy Working...
*
* @author shankar
*/
public class ImportFile implements DalBaseProcess{
private static Logger log=Logger.getLogger(ImportFile.class);
public void execute(ProcessBundle bundle) throws Exception {
try{
String RecordId=(String) bundle.getParams().get("XXX_Import_ID");
log.info("Record ID "+RecordId);
String sourcepath= OBPropertiesProvider.getInstance().getOpenbravoProperties().getProperty("source.path");
String dburl= OBPropertiesProvider.getInstance().getOpenbravoProperties().getProperty("bbdd.url");
String database = OBPropertiesProvider.getInstance().getOpenbravoProperties().getProperty("bbdd.sid");
String systemUser = OBPropertiesProvider.getInstance().getOpenbravoProperties().getProperty("bbdd.systemUser");
String systemPassword = OBPropertiesProvider.getInstance().getOpenbravoProperties().getProperty("bbdd.systemPassword");
}
catch(Exception e){
}
}
Comments Off
Retrieving last changed value in Openbravo Callout
July 7th, 2011Callout in Openbravo is the feature that enables us to do runtime operations with the data. Callout is generally attached to a field and triggered in the onchange event. Openbravo has implemented a java class file called SimpleCallout.java, that we can extend and use it for implementing Callouts. For more information on implementing callouts, refer here and here.
As Callouts are attached to a field, you can use the field name with the prefix 'inp' to retrieve the run time value. Based upon that, you can do manipulations. But using this method, restrict the usage of that callout to a particular field. Say for instance I have a same logic to be implemented across five different fields, then I have to write 5 different callout, as we are hard coding the field names. But there is also a method provided to retrieve the last changed field and then using that, you can retrieve that value.
I have provided below the code, that retrieves the name of the last changed field and then the value of the corresponding field.
package com.fugoconsulting.xxx.erpCommon.ad_callout;Happy Working...
import javax.servlet.ServletException;
import java.util.*;
import java.lang.*;
import org.openbravo.utils.FormatUtilities;
import org.apache.log4j.Logger;
import org.hibernate.criterion.Expression;
import org.openbravo.erpCommon.ad_callouts.SimpleCallout;
import org.openbravo.base.secureApp.VariablesSecureApp;
import org.openbravo.dal.service.OBDal;
public class NameValidation extends SimpleCallout {
private static final long serialVersionUID = 1L;
private static Logger log = Logger.getLogger(NameValidation.class);
@Override
protected void execute(CalloutInfo info) throws ServletException {
//Gets the last changed field
String lastChanged = info.getStringParameter("inpLastFieldChanged",null);
int length = lastChanged.length();
//Gets the value of the last changed field
String lastChangedValue = info.getStringParameter(lastChanged,null);
log.info("Last field changed:"+lastChanged);
log.info("Last field length:"+length);
}
}
Comments Off
HTMLArea in Openbravo
June 21st, 2011References are a key feature that one should be aware of in OpenbravoERP. References provides us options to change the way a field is displayed in the Application. There are many standard reference types like, Table, TableDir, Date, Integer, ImageBlob, etc. These are mainly bundled inside the WAD. In addition to the existing list of references listed here, one can add more references like RadioButton, FileDialog, etc. For more information on how to extend a base reference to your module, refer here.
HtmlArea Reference:
The use of this reference type it to display the value based on the html code provided. It can be used in many scenarios. I have provided a basic few scenarios here.
- To display different colour on the field based on the condition.
- To display remote content in the field.
- To embed HTML code available elsewhere.
- Used when you want to have a link to any other openbravo window or process. This is can done by using <a href="link"/> where link is the url of that corresponding window or process.
- For simple formatting like Font Color, Background Image, etc.
Compile the application and the output will be as follows.
Steps:
Add the following files in Openbravo-Source/src-wad/src/org/openbravo/wad/controls
1. WADHtml.html
2. WADHtml.java<?xml version="1.0" encoding="UTF-8" ?> <!-- ********************************************************* @author Pandeeswari ********************************************************* --> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <script type="text/javascript"> function DisplayHtml(/*String */ id) { var htmlValue = document.getElementById(id); var displayText = document.getElementById('yy'); displayText.innerHTML = htmlValue.value; htmlValue.style.display = 'none'; } </script> </head> <body> <FIELD_TMP> <div id="xx_inp"> <table border="0" cellpadding="0" cellspacing="0"> <tr> <td> <table style="border:0px;border-collapse:collapse;"> <tr> <td style="padding-top: 0px;"> <textarea id="xx" required="false" maxlength='xx' name="inpxx" onkeyup="" onkeydown="changeToEditingMode('onkeydown');" onkeypress="changeToEditingMode('onkeypress');" oncut="changeToEditingMode('oncut');" onpaste="changeToEditingMode('onpaste');" oncontextmenu="changeToEditingMode('oncontextmenu');" onchange="validateTextArea(this.id);logChanges(this);xx();return true;" onfocus="DisplayHtml(this.id);"></textarea> <b id="yy" required="false" maxlength='xx' onkeyup="" onkeydown="" onkeypress="" oncut="" onpaste="" oncontextmenu="" onchange=""></b> </td> </tr> </table> <span style="display: none;" id="xxmissingSpan"> <table> <tr> <td><div /></td><td></td> </tr> <tr> <td colspan="2" class='missing'><div id="xxmissingSpanText" name="missingText">xx</div></td> </tr> </table> </span> </td> </tr> </table> </div> </FIELD_TMP> </body> </html>
3. WADHtml.xml/* ********************************************************* @author Pandeeswari ********************************************************* */ package org.openbravo.wad.controls; import java.io.IOException; import java.util.Properties; import java.util.Vector; import javax.servlet.ServletException; import org.openbravo.wad.EditionFieldsData; import org.openbravo.wad.FieldsData; import org.openbravo.wad.WadUtility; import org.openbravo.xmlEngine.XmlDocument; public class WADHtml extends WADControl { public WADHtml() { } public WADHtml(Properties prop) { setInfo(prop); initialize(); } public void initialize() { generateJSCode(); } private void generateJSCode() { addImport("ValidationTextArea", "../../../../../web/js/default/ValidationTextArea.js"); if (getData("IsMandatory").equals("Y")) { XmlDocument xmlDocument = getReportEngine().readXmlTemplate( "org/openbravo/wad/controls/WADMemoJSValidation").createXmlDocument(); xmlDocument.setParameter("columnNameInp", getData("ColumnNameInp")); setValidation(replaceHTML(xmlDocument.print())); } setCalloutJS(); } public String getType() { return "TextArea"; } public String editMode() { double rowLength = ((Integer.valueOf(getData("FieldLength")).intValue() * 20) / 4000); if (rowLength < 3.0) rowLength = 3.0; XmlDocument xmlDocument = getReportEngine().readXmlTemplate( "org/openbravo/wad/controls/WADHtml").createXmlDocument(); xmlDocument.setParameter("columnName", getData("ColumnName")); xmlDocument.setParameter("columnNameInp", getData("ColumnNameInp")); xmlDocument.setParameter("size", getData("CssSize")); xmlDocument.setParameter("maxlength", getData("FieldLength")); boolean isDisabled = (getData("IsReadOnly").equals("Y") || getData("IsReadOnlyTab").equals("Y") || getData( "IsUpdateable").equals("N")); xmlDocument.setParameter("disabled", (isDisabled ? "Y" : "N")); if (!isDisabled && getData("IsMandatory").equals("Y")) { xmlDocument.setParameter("required", "true"); xmlDocument.setParameter("requiredClass", " required"); } else { xmlDocument.setParameter("required", "false"); xmlDocument.setParameter("requiredClass", (isDisabled ? " readonly" : "")); } xmlDocument.setParameter("callout", getOnChangeCode()); return replaceHTML(xmlDocument.print()); } public String newMode() { double rowLength = ((Integer.valueOf(getData("FieldLength")).intValue() * 20) / 4000); if (rowLength < 3.0) rowLength = 3.0; XmlDocument xmlDocument = getReportEngine().readXmlTemplate( "org/openbravo/wad/controls/WADHtml").createXmlDocument(); xmlDocument.setParameter("columnName", getData("ColumnName")); xmlDocument.setParameter("columnNameInp", getData("ColumnNameInp")); xmlDocument.setParameter("size", getData("CssSize")); xmlDocument.setParameter("maxlength", getData("FieldLength")); boolean isDisabled = (getData("IsReadOnly").equals("Y") || getData("IsReadOnlyTab").equals("Y")); xmlDocument.setParameter("disabled", (isDisabled ? "Y" : "N")); if (!isDisabled && getData("IsMandatory").equals("Y")) { xmlDocument.setParameter("required", "true"); xmlDocument.setParameter("requiredClass", " required"); } else { xmlDocument.setParameter("required", "false"); xmlDocument.setParameter("requiredClass", (isDisabled ? " readonly" : "")); } xmlDocument.setParameter("callout", getOnChangeCode()); return replaceHTML(xmlDocument.print()); } public String toXml() { String[] discard = { "xx_PARAM", "xx_PARAMHIDDEN", "xx_HIDDEN" }; if (getData("IsDisplayed").equals("N")) { if (getData("IsParameter").equals("Y")) discard[1] = "xx"; else discard[2] = "xx"; } else { if (getData("IsParameter").equals("Y")) discard[0] = "xx"; } XmlDocument xmlDocument = getReportEngine().readXmlTemplate( "org/openbravo/wad/controls/WADMemoXML", discard).createXmlDocument(); xmlDocument.setParameter("columnName", getData("ColumnName")); return replaceHTML(xmlDocument.print()); } public String toJava() { return ""; } public void processTable(String strTab, Vector<Object> vecFields, Vector<Object> vecTables, Vector<Object> vecWhere, Vector<Object> vecOrder, Vector<Object> vecParameters, String tableName, Vector<Object> vecTableParameters, FieldsData field, Vector<String> vecFieldParameters, Vector<Object> vecCounters) throws ServletException, IOException { // Override this to do nothing } }
Using the above code, create the reference as follows. Specify the reference type as Html Area in columns for the desired column(It should be character varying in Database). Give the html code and compile. Then when you open the window in classic mode, and based upon the code provided in HTML, the value will be displayed. There are some points to be noted here.<?xml version="1.0" encoding="UTF-8"?> <!-- ********************************************************* @author Pandeeswari ********************************************************* --> <REPORT> <template file="WADHtml.html"/> <PARAMETER id="paramChecked" name="checked" default="Y"/> <PARAMETER id="xx_inp" name="columnName" attribute="id" replace="xx"/> <PARAMETER id="xx" name="columnName" attribute="id"/> <PARAMETER id="xx" name="columnNameInp" attribute="name" replace="xx"/> <PARAMETER id="xx" name="size" attribute="class" replace="yy"/> <PARAMETER id="xx" name="callout" attribute="onchange" replace="xx();"/> <PARAMETER id="xx" name="maxlength" attribute="maxlength"/> <PARAMETER id="xx" name="disabled" boolean="readonly=true" withId="paramChecked"/> <PARAMETER id="xx" name="required" attribute="required"/> <PARAMETER id="xx" name="requiredClass" attribute="class" replace="xx"/> <PARAMETER id="xxmissingSpan" name="columnName" attribute="id" replace="xx"/> <PARAMETER id="xxmissingSpanText" name="columnName" attribute="id" replace="xx"/> <DISCARD id="discard"/> </REPORT>
- This reference type works currently in Classic mode.
- In the form view, the HTML output gets displayed, but in the Grid view, the HTML code gets displayed.
- Only if the corresponding field is the First field in the page or the first focussed field, then HTML output gets displayed. Or else the HTML code alone appears and once the focus is changed from that field, the HTML output appears as I have written the function in the onblurevent.
- The same code can be extended to support scripts and also Data Operations.
- Modifying core code is not advised by Openbravo. Its better to go for a Modular approach and bundle the custom reference as a separate module. Since I have provided a prototype, I have modified core.
- A proper implementation of the same with OB3 modules will be done soon and updated..:)
Comments and suggestions are very much welcome.
Comments Off
Creating Charts in Openbravo Reports
June 10th, 2011Reporting is a decisive factor that determines the reach of an ERP among the Users. OpenbravoERP in particular have laid a lot of emphasis on the reporting structures. iReport is the tool officially supported by Openbravo for generating reports within Openbravo.For basic on developing reports in iReport, refer here. You can download iReport here.
iReport is an opensource java based reporting tool. iReport provides lots of features like sub-reports,crosstab references, and various presentation gadgets like charts, bar graph, plotted line, etc. I have provided the steps for creating charts in reports in Openbravo.
Lets see an example. I have 10 product categories and 500 products. I want to see which products fall under which category and how much is the stock available. Lets see how this could look.
If you have not worked in iReports before, you can take a look at this. You can download iReport here. To add a chart to a window, use the chart tool icon in the interface. A screen shot of where it is located is provided below:
Once you have added the chart, you can access the chart properties as provided in the below screen shot.

In the chart properties, go to chart data -> details. Here you can add the categories based upon which you want the data. Here I have added the category as product Category and the series values in terms of the products in that particular category. Here the following key points to be noted are:
1. Series Expression:
This represents the bars that appears on the chart. Here we want all the products with the count. so we choose the products here.
2. Category Expression:
This represents the x-axis. Here the product category is our base and we provide that here.
3. Value Expression
Value is nothing but the quantity that determines the height of the bars in the report. Here we are providing the count of each product.
4. Label Expression (optional)
This provides the additional information about the bars in the chart that is provided under the chart. If its left empty, the name from the value expression will be pulled up.

Once all this is done, refer to the steps to import the same in the Openbravo Application and if you run the report, you will get the following output.

There are three presentation output types provided by Openbravo. You can use that by defining a parameter called output type. This will help us to view the report as Html, Excel, PDF. Note that when you are using charts or any images like these, it will come properly only in PDF or Excel view. The html view may not present the image. Having presented all this, generating reports in this format is really helpful. However Openbravo has now become the agile, tamed ERP...:). There is a new and powerful feature called widgets. You can gather more information about it here.
Comments Off























