# HG changeset patch
# User Naroa Iriarte <naroa.iriarte@openbravo.com>
# Date 1467216610 -7200
#      Wed Jun 29 18:10:10 2016 +0200
# Node ID 36d8754e43314bd4efbdb8c9f85ce6aa8a01b409
# Parent  cc5f703395d681b92315cdc21d19642e4f549101
Fixed issue 33003: The titles in the CSV were wrong

If there was a property field, the titles of those columns were wrong
when exporting to csv.
The problem was in the QueryJSONWriterToCSV inner class of the DataSourceServlet class.
Here wher exporting to csv there was only taking into account if the column of the field
was the same of the column checked in the iteration. The problem occurs when there are
two or more fields which have the same column.
Now the condition has been changed, first it checks if the current field is a property field
and if the property is the one we really want.

diff --git a/modules/org.openbravo.service.datasource/src/org/openbravo/service/datasource/DataSourceServlet.java b/modules/org.openbravo.service.datasource/src/org/openbravo/service/datasource/DataSourceServlet.java
--- a/modules/org.openbravo.service.datasource/src/org/openbravo/service/datasource/DataSourceServlet.java
+++ b/modules/org.openbravo.service.datasource/src/org/openbravo/service/datasource/DataSourceServlet.java
@@ -413,10 +413,11 @@
 
           boolean preferenceCalculateFirst = true;
           boolean translateYesNoReferences = false;
+          String formatedPropKey = "";
           for (String propKey : properties.keySet()) {
             final Property prop = properties.get(propKey);
             Column col = OBDal.getInstance().get(Column.class, prop.getColumnId());
-
+            formatedPropKey = propKey.replace("$", ".");
             if (prop.isAuditInfo()) {
               Element element = null;
               if ("creationDate".equals(propKey)) {
@@ -439,9 +440,13 @@
               Tab tab = OBDal.getInstance().get(Tab.class,
                   parameters.get(JsonConstants.TAB_PARAMETER));
               for (Field field : tab.getADFieldList()) {
-                if (field.getColumn() == null || !field.getColumn().getId().equals(col.getId())) {
+                if (field.getProperty() != null && !formatedPropKey.equals(field.getProperty())) {
+                  continue;
+                } else if (field.getColumn() == null
+                    || !field.getColumn().getId().equals(col.getId())) {
                   continue;
                 }
+
                 niceFieldProperties.put(propKey, field.getName());
                 for (FieldTrl fieldTrl : field.getADFieldTrlList()) {
                   if (fieldTrl.getLanguage().getId().equals(userLanguageId)) {
