fixed issue 16464: Handle translations in grid
authorAsier Lostalé <asier.lostale@openbravo.com>
Mon, 18 Jul 2011 12:27:04 +0200
changeset 13225 389abd2b89f7
parent 13224 af0539a25f8c
child 13226 f7319ac66cd2
fixed issue 16464: Handle translations in grid

Filter taking into account translations
modules/org.openbravo.service.json/src/org/openbravo/service/json/AdvancedQueryBuilder.java
--- a/modules/org.openbravo.service.json/src/org/openbravo/service/json/AdvancedQueryBuilder.java	Mon Jul 18 12:26:21 2011 +0200
+++ b/modules/org.openbravo.service.json/src/org/openbravo/service/json/AdvancedQueryBuilder.java	Mon Jul 18 12:27:04 2011 +0200
@@ -884,7 +884,27 @@
       }
       // note to_char is added to handle null values correctly
       if (prop.getReferencedProperty() == null) {
-        sb.append("COALESCE(to_char(" + prefix + prop.getName() + "),'')");
+        if (prop.isTranslatable()) {
+          // HQL for trl properties. Doing it as a select because it cannot be done as left join.
+          // Example:
+          //
+          // select coalesce(w.name, t.name)
+          // from ADWindow w left join w.aDWindowTrlList as t with t.language = :lang
+          // where w.id=:window
+          //
+          // raises: with clause can only reference columns in the driving table
+
+          sb.append("COALESCE(to_char((select " + prop.getTranslationProperty().getName()
+              + " from " + prop.getTranslationProperty().getEntity().getName() + " as t where t."
+              + prop.getTrlParentProperty().getName() + " = "
+              + prefix.substring(0, prefix.lastIndexOf('.')) + " and t.language.language='"
+              + OBContext.getOBContext().getLanguage().getLanguage() + "')), to_char(" + prefix
+              + prop.getName() + "), '')");
+
+        } else {
+          sb.append("COALESCE(to_char(" + prefix + prop.getName() + "),'')");
+        }
+
       } else {
         final List<Property> newIdentifierProperties = prop.getReferencedProperty().getEntity()
             .getIdentifierProperties();