Fixes issue 30132: Product Transactions tab not showing records after filtering
authorCarlos Aristu <carlos.aristu@openbravo.com>
Fri, 12 Jun 2015 10:32:21 +0200
changeset 26904 4b256593c263
parent 26903 a14340555783
child 26906 91f6d8a87c92
child 26911 ebf462f93acf
Fixes issue 30132: Product Transactions tab not showing records after filtering

The problem happened on the client filtering. In this case, the id of the property that references the parent tab is included in the criteria (using the convertCriteria function of the OBViewGrid class).
For those tabs which does not have any property (column) marked as link to parent, the parent property was not being requested to the datasource and when applying the criteria on the local filter the value for the parent property in every record was undefined. That was the reason why the filtering was not returning any record.
Now if the tab does not have any property set as link to parent, we look for the property pointing to the parent tab and include it in the selected properties returned by the datasource.
modules/org.openbravo.client.application/src/org/openbravo/client/application/window/OBViewGridComponent.java
--- a/modules/org.openbravo.client.application/src/org/openbravo/client/application/window/OBViewGridComponent.java	Thu Jun 11 20:40:59 2015 +0000
+++ b/modules/org.openbravo.client.application/src/org/openbravo/client/application/window/OBViewGridComponent.java	Fri Jun 12 10:32:21 2015 +0200
@@ -27,6 +27,7 @@
 import org.openbravo.base.model.Entity;
 import org.openbravo.base.model.ModelProvider;
 import org.openbravo.base.model.Property;
+import org.openbravo.client.application.ApplicationUtils;
 import org.openbravo.client.application.GCSystem;
 import org.openbravo.client.application.GCTab;
 import org.openbravo.client.application.window.OBViewFieldHandler.OBViewField;
@@ -297,10 +298,19 @@
       requiredGridProperties.add(propertyName);
     }
 
-    // Always include the propertyt that links to the parent tab
+    // Always include the property that links to the parent tab
     String linkToParentPropertyName = this.getLinkToParentPropertyName();
     if (linkToParentPropertyName != null && !linkToParentPropertyName.isEmpty()) {
       requiredGridProperties.add(linkToParentPropertyName);
+    } else {
+      // See issue https://issues.openbravo.com/view.php?id=30132
+      // If the child tab does not have a property marked as link to parent, look for the property
+      // in the entity of the tab pointing to the parent tab
+      String parentPropertyName = this.getParentPropertyName();
+      if (parentPropertyName != null && !parentPropertyName.isEmpty()
+          && !requiredGridProperties.contains(parentPropertyName)) {
+        requiredGridProperties.add(parentPropertyName);
+      }
     }
 
     // Include the Stored in Session properties
@@ -398,6 +408,20 @@
     return null;
   }
 
+  private String getParentPropertyName() {
+    Tab parentTab = KernelUtils.getInstance().getParentTab(tab);
+    if (parentTab == null) {
+      return null;
+    }
+    String parentProperty = null;
+    // If the parentTab uses the same table, we don't do nothing because the id is the parent
+    // property and it is always included
+    if (!tab.getTable().getId().equals(parentTab.getTable().getId())) {
+      parentProperty = ApplicationUtils.getParentProperty(tab, parentTab);
+    }
+    return parentProperty;
+  }
+
   /**
    * Returns true if the grid should filter and sort lazily. In that case, the changes done by the
    * user to filter editor and to the grid sorting will not by applied until the user clicks on an