26696: Table references work with display column other than identifiers
authorShankar Balachandran <shankar.balachandran@openbravo.com>
Sun, 22 Jun 2014 12:27:58 +0530
changeset 23858 e3da458ad088
parent 23857 bc7151f88085
child 23859 4639ca577e0b
26696: Table references work with display column other than identifiers

When table references were displayed, always the identifier columns were displayed.
The actual value was displayed in cases of composite identifiers which in turn was another identifier,
eg., Financial account in Customer. Now it uses the display column in all cases.
The criteriaDisplayField parameter is already being used for displaying the appropriate value. Set it's value correctly for table references
Added additional logic in DefaultJsonDataService to include the display field column to the formed BOB object.
This fix is not risky as it affects only the displaying of FK filter values from the fetched result.
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/formitem/ob-formitem-fk-filter.js
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/grid/ob-grid.js
modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/reference/FKComboUIDefinition.java
modules/org.openbravo.service.json/src/org/openbravo/service/json/DefaultJsonDataService.java
modules/org.openbravo.service.json/src/org/openbravo/service/json/JsonConstants.java
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/formitem/ob-formitem-fk-filter.js	Mon Jun 23 16:12:52 2014 +0530
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/formitem/ob-formitem-fk-filter.js	Sun Jun 22 12:27:58 2014 +0530
@@ -72,6 +72,10 @@
         if (gridView) {
           requestProperties.params.tabId = gridView.tabId || (gridView.sourceView && gridView.sourceView.tabId);
         }
+        //send the display field in request params to add it to the list of fields to be fetched.
+        if (this.formItem && this.formItem.displayField) {
+          requestProperties.params.displayField = this.formItem.displayField;
+        }
         delete me.forceReload;
       },
 
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/grid/ob-grid.js	Mon Jun 23 16:12:52 2014 +0530
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/grid/ob-grid.js	Sun Jun 22 12:27:58 2014 +0530
@@ -597,6 +597,10 @@
           field.filterEditorProperties.criteriaField = field.criteriaField;
         }
 
+        if (field.criteriaDisplayField) {
+          field.filterEditorProperties.criteriaDisplayField = field.criteriaDisplayField;
+        }
+
         if (field.editorType && new Function('return isc.' + field.editorType + '.getPrototype().isAbsoluteTime')()) {
           // In the case of an absolute time, the time needs to be converted in order to avoid the UTC conversion
           // http://forums.smartclient.com/showthread.php?p=116135
--- a/modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/reference/FKComboUIDefinition.java	Mon Jun 23 16:12:52 2014 +0530
+++ b/modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/reference/FKComboUIDefinition.java	Sun Jun 22 12:27:58 2014 +0530
@@ -25,7 +25,6 @@
 import org.openbravo.client.kernel.KernelUtils;
 import org.openbravo.dal.core.DalUtil;
 import org.openbravo.model.ad.datamodel.Column;
-import org.openbravo.model.ad.datamodel.Table;
 import org.openbravo.model.ad.domain.Reference;
 import org.openbravo.model.ad.domain.ReferencedTable;
 import org.openbravo.model.ad.ui.Field;
@@ -60,8 +59,9 @@
       Reference referenceSearchKey = column.getReferenceSearchKey();
       if (referenceSearchKey != null && referenceSearchKey.getADReferencedTableList().size() > 0) {
         ReferencedTable referencedTable = referenceSearchKey.getADReferencedTableList().get(0);
-        if (referencedTable != null
-            && isTableWithMultipleIdentifierColumns(referencedTable.getTable())) {
+        // set the criteriaDisplayField in all cases, as the display column need not be part of
+        // identifier. Refer issue https://issues.openbravo.com/view.php?id=26696
+        if (referencedTable != null) {
           Property prop = KernelUtils.getInstance().getPropertyFromColumn(column);
           Property referencedProp = KernelUtils.getInstance().getPropertyFromColumn(
               referencedTable.getDisplayedColumn());
@@ -76,22 +76,6 @@
     return super.getGridFieldProperties(field) + criteriaField;
   }
 
-  /* Returns true if the identifier of the table is composed of more than one column */
-  private Boolean isTableWithMultipleIdentifierColumns(Table relatedTable) {
-    int nIdentifiers = 0;
-    for (Column curColumn : relatedTable.getADColumnList()) {
-      if (curColumn.isIdentifier()) {
-        nIdentifiers += 1;
-        if (nIdentifiers > 1) {
-          // if there is more than one identifier return true
-          return true;
-        }
-      }
-    }
-    // there is only one identifier column
-    return false;
-  }
-
   @Override
   public String getFieldProperties(Field field, boolean getValueFromSession) {
     JSONObject value;
--- a/modules/org.openbravo.service.json/src/org/openbravo/service/json/DefaultJsonDataService.java	Mon Jun 23 16:12:52 2014 +0530
+++ b/modules/org.openbravo.service.json/src/org/openbravo/service/json/DefaultJsonDataService.java	Sun Jun 22 12:27:58 2014 +0530
@@ -84,11 +84,33 @@
    */
   public String fetch(Map<String, String> parameters) {
     try {
+      boolean propertyPresent = false;
       final String entityName = parameters.get(JsonConstants.ENTITYNAME);
       Check.isNotNull(entityName, "The name of the service/entityname should not be null");
       Check.isNotNull(parameters, "The parameters should not be null");
 
       String selectedProperties = parameters.get(JsonConstants.SELECTEDPROPERTIES_PARAMETER);
+      String displayField = parameters.get(JsonConstants.DISPLAYFIELD_PARAMETER);
+      /**
+       * if displayField parameter is present, combo field's filter method is being called. in this
+       * case if the field is a table reference, add the displayed column to list of columns to be
+       * retrieved. Refer issue https://issues.openbravo.com/view.php?id=26696
+       */
+      if (StringUtils.isNotEmpty(displayField)) {
+        for (String selectedProp : selectedProperties.split(",")) {
+          if (selectedProp.equals(displayField)) {
+            propertyPresent = true;
+            break;
+          }
+        }
+        if (!propertyPresent) {
+          if (StringUtils.isNotEmpty(selectedProperties)) {
+            selectedProperties = selectedProperties.concat("," + displayField);
+          } else {
+            selectedProperties = displayField;
+          }
+        }
+      }
 
       final JSONObject jsonResult = new JSONObject();
       final JSONObject jsonResponse = new JSONObject();
--- a/modules/org.openbravo.service.json/src/org/openbravo/service/json/JsonConstants.java	Mon Jun 23 16:12:52 2014 +0530
+++ b/modules/org.openbravo.service.json/src/org/openbravo/service/json/JsonConstants.java	Sun Jun 22 12:27:58 2014 +0530
@@ -69,6 +69,7 @@
   public static final String TEXTMATCH_EXACT = "exact";
   public static final String TEXTMATCH_STARTSWITH = "startsWith";
   public static final String TEXTMATCH_SUBSTRING = "substring";
+  public static final String DISPLAYFIELD_PARAMETER = "displayField";
 
   // if this parameter is passed then if a new object already has an id then
   // that id is set back in the json which is returned together with the