# HG changeset patch
# User Inigo Sanchez <inigo.sanchez@openbravo.com>
# Date 1480290516 -3600
#      Mon Nov 28 00:48:36 2016 +0100
# Node ID abcee2147a913ad115a830af2b759e1b4af0e51e
# Parent  3d24fc9233285a621a20c0da0ae464cffee7c6f0
Fixed issue 34324:Summary functions do not work in tabs based on HQL queries.

The summary functions didn't work in tabs based on HQL queries because this
functionality was not developed. The HQLDataSourceService hadn't the code to
managed summary functions properly.

To avoid this problem, it has been resolved by blocking the use of the summary
functions in the tabs based on HQL query.

diff -r 3d24fc923328 -r abcee2147a91 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	Sun Nov 27 21:10:20 2016 +0100
+++ b/modules/org.openbravo.client.application/src/org/openbravo/client/application/window/OBViewGridComponent.java	Mon Nov 28 00:48:36 2016 +0100
@@ -28,6 +28,7 @@
 import org.openbravo.base.model.Entity;
 import org.openbravo.base.model.ModelProvider;
 import org.openbravo.base.model.Property;
+import org.openbravo.client.application.ApplicationConstants;
 import org.openbravo.client.application.ApplicationUtils;
 import org.openbravo.client.application.GCSystem;
 import org.openbravo.client.application.GCTab;
@@ -408,11 +409,12 @@
   }
 
   /**
-   * Returns true if the grid allows adding summary functions
+   * Returns true if the grid allows adding summary functions. If tab is based on a HQL table,
+   * summary functions are disabled.
    */
   public boolean getAllowSummaryFunctions() {
-    return isConfigurationPropertyEnabled(GCTab.PROPERTY_ALLOWSUMMARYFUNCTIONS,
-        GCSystem.PROPERTY_ALLOWSUMMARYFUNCTIONS, true);
+    return (isHqlTable(this.tab.getTable()) ? false : isConfigurationPropertyEnabled(
+        GCTab.PROPERTY_ALLOWSUMMARYFUNCTIONS, GCSystem.PROPERTY_ALLOWSUMMARYFUNCTIONS, true));
   }
 
   private boolean isConfigurationPropertyEnabled(String propertyNameAtTabLevel,
@@ -459,7 +461,11 @@
 
   public String getTableAlias() {
     Table table = tab.getTable();
-    return "HQL".equals(table.getDataOriginType()) && !StringUtils.isBlank(table.getEntityAlias()) ? table
+    return isHqlTable(table) && !StringUtils.isBlank(table.getEntityAlias()) ? table
         .getEntityAlias() : "e";
   }
+
+  private boolean isHqlTable(Table table) {
+    return ApplicationConstants.HQLBASEDTABLE.equals(table.getDataOriginType());
+  }
 }
