details:   https://code.openbravo.com/erp/devel/pi/rev/e3da458ad088
changeset: 23858:e3da458ad088
user:      Shankar Balachandran <shankar.balachandran <at> openbravo.com>
date:      Sun Jun 22 12:27:58 2014 +0530
summary:   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.

diffstat:

 
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/formitem/ob-formitem-fk-filter.js
 |   4 +
 
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/grid/ob-grid.js
                        |   4 +
 
modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/reference/FKComboUIDefinition.java
                  |  22 +--------
 
modules/org.openbravo.service.json/src/org/openbravo/service/json/DefaultJsonDataService.java
                           |  22 ++++++++++
 
modules/org.openbravo.service.json/src/org/openbravo/service/json/JsonConstants.java
                                    |   1 +
 5 files changed, 34 insertions(+), 19 deletions(-)

diffs (122 lines):

diff -r bc7151f88085 -r e3da458ad088 
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/formitem/ob-formitem-fk-filter.js
--- 
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;
       },
 
diff -r bc7151f88085 -r e3da458ad088 
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/grid/ob-grid.js
--- 
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
diff -r bc7151f88085 -r e3da458ad088 
modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/reference/FKComboUIDefinition.java
--- 
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;
diff -r bc7151f88085 -r e3da458ad088 
modules/org.openbravo.service.json/src/org/openbravo/service/json/DefaultJsonDataService.java
--- 
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();
diff -r bc7151f88085 -r e3da458ad088 
modules/org.openbravo.service.json/src/org/openbravo/service/json/JsonConstants.java
--- 
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

------------------------------------------------------------------------------
HPCC Systems Open Source Big Data Platform from LexisNexis Risk Solutions
Find What Matters Most in Your Big Data with HPCC Systems
Open Source. Fast. Scalable. Simple. Ideal for Dirty Data.
Leverages Graph Analysis for Fast Processing & Easy Data Exploration
http://p.sf.net/sfu/hpccsystems
_______________________________________________
Openbravo-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to