fixed bug 15860: In 2.50 grid parent field name is translated
authorAsier Lostalé <asier.lostale@openbravo.com>
Fri, 04 Mar 2011 13:25:30 +0100
changeset 11023 384c1d0213d8
parent 11022 ccf67943c792
child 11024 cbfce7570f7e
fixed bug 15860: In 2.50 grid parent field name is translated
src-wad/src/org/openbravo/wad/Configuration_Relation.xmlxml
src-wad/src/org/openbravo/wad/Fields_data.xsql
src-wad/src/org/openbravo/wad/Template_Relation.html
src-wad/src/org/openbravo/wad/Template_Relation.xml
src-wad/src/org/openbravo/wad/Wad.java
src-wad/src/org/openbravo/wad/javasource.javaxml
src-wad/src/org/openbravo/wad/javasource.xml
src/org/openbravo/erpCommon/businessUtility/AuditTrailPopup_data.xsql
src/org/openbravo/erpCommon/utility/Utility.java
--- a/src-wad/src/org/openbravo/wad/Configuration_Relation.xmlxml	Fri Mar 04 13:04:56 2011 +0100
+++ b/src-wad/src/org/openbravo/wad/Configuration_Relation.xmlxml	Fri Mar 04 13:25:30 2011 +0100
@@ -51,6 +51,7 @@
 <PARAMETER_TMP id="sectionParent">
 <PARAMETER id="paramParentxx" name="parent" default=""/></PARAMETER_TMP>
 <PARAMETER_TMP id="relationControl"></PARAMETER_TMP>
+<PARAMETER id="related_info_cont" name="parentFieldName"/> 
 
 <DISCARD id="discard"/>
 </REPORT>
--- a/src-wad/src/org/openbravo/wad/Fields_data.xsql	Fri Mar 04 13:04:56 2011 +0100
+++ b/src-wad/src/org/openbravo/wad/Fields_data.xsql	Fri Mar 04 13:25:30 2011 +0100
@@ -36,7 +36,7 @@
         isParent, '' as ACCESSLEVEL, ad_field.isreadonly, '' as issecondarykey, ad_field.showInRelation, ad_column.isEncrypted,
         ad_field.SORTNO, ad_column.istranslated, '' as id, '' as htmltext, '' as htmltexttrl, '' as xmltexttrl, '' as tablenametrl, 
         0 AS NOWRAP, ad_column.isEncrypted AS isColumnEncrypted, ad_column.isDesencryptable, ad_reference_value_id, ad_column.ad_val_rule_id, '' AS isjasper, ad_field.isactive, '' as AD_Tab_ID, '' as parent_tab_name, '' as orgcode,
-        '' as tableModule, '' as columnModule, '' as clientcode, '' as isautosave
+        '' as tableModule, '' as columnModule, '' as clientcode, '' as isautosave, '' as ad_field_id
       FROM ad_column left join ad_element on ad_column.ad_element_id = ad_element.ad_element_id,
            ad_field,  ad_table
       WHERE ad_field.ad_column_id = ad_column.ad_column_id 
@@ -102,7 +102,7 @@
   <SqlMethod name="parentsColumnNameSortTab" type="preparedStatement" return="multiple">
       <SqlMethodComment>Name of the columns parent of the tab</SqlMethodComment>
       <Sql><![CDATA[
-        SELECT ColumnName AS NAME, AD_REFERENCE_id AS reference, ad_reference_value_id AS referencevalue,
+        SELECT AD_FIELD.AD_FIELD_ID, ColumnName AS NAME, AD_REFERENCE_id AS reference, ad_reference_value_id AS referencevalue,
         (SELECT tableNAME FROM AD_TABLE, AD_TAB WHERE AD_TABLE.ad_table_id = AD_TAB.ad_table_id
         AND AD_TAB.ad_tab_id=?) AS tablename,
         (SELECT P.ad_module_id FROM AD_TABLE T, AD_PACKAGE P WHERE T.ad_table_id = AD_COLUMN.ad_table_id AND T.AD_PACKAGE_ID = P.AD_PACKAGE_ID) as tableModule,
@@ -118,7 +118,7 @@
   <SqlMethod name="parentsColumnName" type="preparedStatement" return="multiple">
       <SqlMethodComment>Name of the columns parent of the tab</SqlMethodComment>
       <Sql><![CDATA[
-        SELECT ColumnName AS NAME, AD_REFERENCE_id AS reference, ad_reference_value_id AS referencevalue,
+        SELECT AD_FIELD.AD_FIELD_ID, ColumnName AS NAME, AD_REFERENCE_id AS reference, ad_reference_value_id AS referencevalue,
         (SELECT tableNAME FROM AD_TABLE, AD_TAB WHERE AD_TABLE.ad_table_id = AD_TAB.ad_table_id
         AND AD_TAB.ad_tab_id=?) AS tablename, ? as AD_Tab_ID, (select name from ad_tab where ad_tab_id = ?) as parent_tab_name,
         (SELECT P.ad_module_id FROM AD_TABLE T, AD_PACKAGE P WHERE T.ad_table_id = AD_COLUMN.ad_table_id AND T.AD_PACKAGE_ID = P.AD_PACKAGE_ID) as tableModule,
@@ -139,7 +139,7 @@
   <SqlMethod name="parentsColumnReal" type="preparedStatement" return="multiple">
       <SqlMethodComment>Name of the columns parent of the tab</SqlMethodComment>
       <Sql>
-        SELECT ColumnName AS NAME, AD_REFERENCE_id AS reference, ad_reference_value_id AS referencevalue,
+        SELECT AD_FIELD.AD_FIELD_ID, ColumnName AS NAME, AD_REFERENCE_id AS reference, ad_reference_value_id AS referencevalue,
         (SELECT tableNAME FROM AD_TABLE, AD_TAB WHERE AD_TABLE.ad_table_id = AD_TAB.ad_table_id
         AND AD_TAB.ad_tab_id=?) AS tablename,
         (SELECT P.ad_module_id FROM AD_TABLE T, AD_PACKAGE P WHERE T.ad_table_id = AD_COLUMN.ad_table_id AND T.AD_PACKAGE_ID = P.AD_PACKAGE_ID) as tableModule,
@@ -163,54 +163,6 @@
       <Parameter name="parentTab"/>
       <Parameter name="parentTab"/>
   </SqlMethod>
-
-  <SqlMethod name="parentsColumnDisplayNameSortTab" type="preparedStatement" return="multiple">
-      <SqlMethodComment>Name of the columns parent of the tab</SqlMethodComment>
-      <Sql><![CDATA[
-        SELECT ad_field.name As Name, ad_field_trl.name as columnname 
-          FROM ad_field left join ad_field_trl on ad_field.ad_field_id = ad_field_trl.ad_field_id 
-                                              and ad_field_trl.ad_language = ?, 
-               ad_column 
-        WHERE ad_field.ad_column_id = ad_column.ad_column_id 
-        and ad_table_id = ? and isParent='Y' 
-      ]]></Sql>
-      <Parameter name="adLanguage"/>
-      <Parameter name="table"/>
-  </SqlMethod>
-  <SqlMethod name="parentsColumnDisplayName" type="preparedStatement" return="multiple">
-      <SqlMethodComment>Name of the columns parent of the tab</SqlMethodComment>
-      <Sql><![CDATA[
-        SELECT ad_field.name As Name, ad_field_trl.name as columnname 
-          FROM ad_field left join ad_field_trl on ad_field.ad_field_id = ad_field_trl.ad_field_id 
-                                              and ad_field_trl.ad_language = ?, 
-               ad_column 
-        WHERE ad_field.ad_column_id = ad_column.ad_column_id 
-        and ad_tab_id = ? and isParent='Y' 
-        and exists(select 1 from ad_column c, ad_field f where c.ad_column_id = f.ad_column_id and c.iskey='Y'
-        and ad_tab_id=? and UPPER(c.columnname) = UPPER(ad_column.columnname))
-      ]]></Sql>
-      <Parameter name="adLanguage"/>
-      <Parameter name="tab"/>
-      <Parameter name="parentTab"/>
-  </SqlMethod>
-  <SqlMethod name="parentsColumnDisplayNameReal" type="preparedStatement" return="multiple">
-      <SqlMethodComment>Name of the columns parent of the tab</SqlMethodComment>
-      <Sql>
-        SELECT ad_field.Name AS NAME, AD_FIELD_TRL.NAME AS COLUMNNAME
-        FROM AD_FIELD left join AD_FIELD_TRL on AD_FIELD.AD_FIELD_ID = AD_FIELD_TRL.AD_FIELD_ID
-                                            AND AD_FIELD_TRL.AD_LANGUAGE = ? , 
-             AD_COLUMN 
-        WHERE AD_FIELD.ad_column_id = AD_COLUMN.ad_column_id 
-        AND ad_tab_id = ?
-        AND UPPER(columnname) IN (SELECT UPPER(columnname) FROM AD_FIELD, AD_COLUMN 
-        WHERE AD_FIELD.ad_column_id = AD_COLUMN.ad_column_id 
-        AND AD_COLUMN.iskey='Y' 
-        AND AD_FIELD.ad_tab_id=?)
-      </Sql>
-      <Parameter name="adLanguage"/>
-      <Parameter name="tab"/>
-      <Parameter name="parentTab"/>
-  </SqlMethod>
  
   <SqlMethod name="tableName" type="preparedStatement" return="string">
       <SqlMethodComment>Name of the table of the tab</SqlMethodComment>
--- a/src-wad/src/org/openbravo/wad/Template_Relation.html	Fri Mar 04 13:04:56 2011 +0100
+++ b/src-wad/src/org/openbravo/wad/Template_Relation.html	Fri Mar 04 13:25:30 2011 +0100
@@ -13,7 +13,7 @@
  * under the License. 
  * The Original Code is Openbravo ERP. 
  * The Initial Developer of the Original Code is Openbravo SLU 
- * All portions are Copyright (C) 2001-2010 Openbravo SLU 
+ * All portions are Copyright (C) 2001-2011 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -288,7 +288,7 @@
                 <div class="RelationInfoContainer">
                   <table class="RelationInfo">
                     <tr>
-                      <td class="RelationInfoTitle" id="related_info_cont"><FIELD_TMP id="fieldParentKeyNameDescription">xx</FIELD_TMP>:</td>
+                      <td class="RelationInfoTitle"><span id="related_info_cont">xx</span>:</td>
                       <td class="RelationInfoContent" id="paramParentxx">Parent name</td>
                     </tr>
                   </table>
--- a/src-wad/src/org/openbravo/wad/Template_Relation.xml	Fri Mar 04 13:04:56 2011 +0100
+++ b/src-wad/src/org/openbravo/wad/Template_Relation.xml	Fri Mar 04 13:25:30 2011 +0100
@@ -12,7 +12,7 @@
  * under the License. 
  * The Original Code is Openbravo ERP. 
  * The Initial Developer of the Original Code is Openbravo SLU 
- * All portions are Copyright (C) 2001-2006 Openbravo SLU 
+ * All portions are Copyright (C) 2001-2011 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -40,7 +40,6 @@
 <PARAMETER id="fieldhiddenKeyName" name="key" default=" " attribute="value"/>
 <PARAMETER id="keyParent" name="keyParent" attribute="name"/>
 <PARAMETER id="paramParentxx" name="parentKeyName" attribute="id" replace="xx" default=""/>
-<PARAMETER id="fieldParentKeyNameDescription" name="parentKeyNameDescription" default=""/>
 
 <DISCARD id="discard"/>
 </REPORT>
--- a/src-wad/src/org/openbravo/wad/Wad.java	Fri Mar 04 13:04:56 2011 +0100
+++ b/src-wad/src/org/openbravo/wad/Wad.java	Fri Mar 04 13:25:30 2011 +0100
@@ -837,27 +837,18 @@
       if (allTabs != null && allTabs.length > 0)
         parentTabIndex = parentTabId(allTabs, tabsData.tabid);
       FieldsData[] parentsFieldsData = null;
-      FieldsData[] parentsFieldsNameData = null;
+
       if (tabsData.issorttab.equals("Y")) {
         parentsFieldsData = FieldsData.parentsColumnNameSortTab(pool,
             (parentTabIndex != -1 ? allTabs[parentTabIndex].tabid : ""), tabsData.tableId);
-        parentsFieldsNameData = FieldsData.parentsColumnDisplayNameSortTab(pool, "",
-            tabsData.tableId);
       } else {
         parentsFieldsData = FieldsData.parentsColumnName(pool,
             (parentTabIndex != -1 ? allTabs[parentTabIndex].tabid : ""), tabsData.tabid);
-        parentsFieldsNameData = FieldsData.parentsColumnDisplayName(pool, "", tabsData.tabid,
-            (parentTabIndex != -1 ? allTabs[parentTabIndex].tabid : ""));
       }
-      String strParentNameDescription = (parentsFieldsNameData == null || parentsFieldsNameData.length == 0) ? ""
-          : parentsFieldsNameData[0].name;
+
       if (parentTabIndex != -1 && (parentsFieldsData == null || parentsFieldsData.length == 0)) {
         parentsFieldsData = FieldsData.parentsColumnReal(pool, allTabs[parentTabIndex].tabid,
             tabsData.tabid);
-        parentsFieldsNameData = FieldsData.parentsColumnDisplayNameReal(pool, "", tabsData.tabid,
-            allTabs[parentTabIndex].tabid);
-        strParentNameDescription = (parentsFieldsNameData == null || parentsFieldsNameData.length == 0) ? ""
-            : parentsFieldsNameData[0].name;
         sinParent = true;
         if (parentsFieldsData == null || parentsFieldsData.length == 0) {
           log4j.warn("No key found in parent tab: " + allTabs[parentTabIndex].tabname);
@@ -1043,7 +1034,7 @@
          *************************************************/
         processTabHtmlSortTab(parentsFieldsData, fileDir, tabsData.tabid, tabName,
             tabsData.realwindowname, keyColumnName, tabNamePresentation, allTabs, strProcess,
-            strDirectPrint, strParentNameDescription, windowName, "");
+            strDirectPrint, windowName, "");
       } else {
         /************************************************
          * JAVA
@@ -1082,8 +1073,8 @@
          * HTML in Relation view
          *************************************************/
         processTabHtmlRelation(parentsFieldsData, fileDir, tabsData.tabid, tabName, keyColumnName,
-            tabsData.uipattern.equals("RO"), strParentNameDescription, gridControl, false, "",
-            tabNamePresentation, tabsData.tableId, tabsData.accesslevel);
+            tabsData.uipattern.equals("RO"), gridControl, false, "", tabNamePresentation,
+            tabsData.tableId, tabsData.accesslevel);
 
         /************************************************
          * XML in Edition view
@@ -1744,6 +1735,7 @@
 
       xmlDocument.setParameter("parentTab", parentsFieldsData[0].adTabId);
       xmlDocument.setParameter("parentTabName", parentsFieldsData[0].parentTabName);
+      xmlDocument.setParameter("parentFieldID", parentsFieldsData[0].adFieldId);
     }
     xmlDocument.setParameter("keyData", Sqlc.TransformaNombreColumna(keyColumnName));
     xmlDocument.setParameter("table", tableName);
@@ -3352,9 +3344,8 @@
    */
   private void processTabHtmlSortTab(FieldsData[] parentsFieldsData, File fileDir, String strTab,
       String tabName, String windowName, String keyColumnName, String tabNamePresentation,
-      TabsData[] allTabs, String strProcess, String strDirectPrint,
-      String strParentNameDescription, String WindowPathName, String strLanguage)
-      throws ServletException, IOException {
+      TabsData[] allTabs, String strProcess, String strDirectPrint, String WindowPathName,
+      String strLanguage) throws ServletException, IOException {
     log4j.debug("Procesig relation sort tab html: " + strTab + ", " + tabName);
     XmlDocument xmlDocumentRHtml;
     final String[] discard = new String[3];
@@ -3440,8 +3431,6 @@
    *          Name of the tab's key column.
    * @param isreadonly
    *          Boolean that means if is a read only tab or not.
-   * @param strParentNameDescription
-   *          The human description of the parent tab.
    * @param control
    *          Object of type WADGrid control.
    * @param isTranslated
@@ -3456,9 +3445,9 @@
    * @throws IOException
    */
   private void processTabHtmlRelation(FieldsData[] parentsFieldsData, File fileDir, String strTab,
-      String tabName, String keyColumnName, boolean isreadonly, String strParentNameDescription,
-      WADControl control, boolean isTranslated, String adLanguage, String tabNamePresentation,
-      String strTable, String accessLevel) throws ServletException, IOException {
+      String tabName, String keyColumnName, boolean isreadonly, WADControl control,
+      boolean isTranslated, String adLanguage, String tabNamePresentation, String strTable,
+      String accessLevel) throws ServletException, IOException {
     log4j.debug("Procesig relation html" + (isTranslated ? " translated" : "") + ": " + strTab
         + ", " + tabName);
     final String[] discard = new String[1];
@@ -3481,7 +3470,6 @@
     if (parentsFieldsData.length > 0) {
       xmlDocument.setParameter("keyParent", "inp"
           + Sqlc.TransformaNombreColumna(parentsFieldsData[0].name));
-      xmlDocument.setParameter("parentKeyNameDescription", strParentNameDescription);
       xmlDocument.setParameter("parentKeyName", parentsFieldsData[0].name);
     }
     xmlDocument.setParameter("importCSS", getVectorElementsNotRepeated(control.getCSSImport(),
--- a/src-wad/src/org/openbravo/wad/javasource.javaxml	Fri Mar 04 13:04:56 2011 +0100
+++ b/src-wad/src/org/openbravo/wad/javasource.javaxml	Fri Mar 04 13:25:30 2011 +0100
@@ -871,7 +871,9 @@
     toolbar.prepareRelationTemplate<PARAMETER_TMP id="sameParent">NoSearch</PARAMETER_TMP>("<PARAMETER_TMP id="paramHasTree">hasTree</PARAMETER_TMP>".equals("Y"), hasSearchCondition, !vars.getSessionValue("#ShowTest", "N").equals("Y"), <PARAMETER_TMP id="paramIsReadOnly">readonly</PARAMETER_TMP>, Utility.getContext(this, vars, "ShowAudit", windowId).equals("Y"));
     xmlDocument.setParameter("toolbar", toolbar.toString());
 
-<PARAMETER_TMP id="parent">    xmlDocument.setParameter("keyParent", strP<PARENT_TMP id="keyParent">Almacen</PARENT_TMP>);</PARAMETER_TMP>
+<PARAMETER_TMP id="parent">    xmlDocument.setParameter("keyParent", strP<PARENT_TMP id="keyParent">Almacen</PARENT_TMP>);
+    xmlDocument.setParameter("parentFieldName", Utility.getFieldName("<PARENT_TMP id="parentFieldID">xx</PARENT_TMP>", vars.getLanguage()));
+</PARAMETER_TMP>
 
     StringBuffer orderByArray = new StringBuffer();
       vars.setSessionValue(tabId + "|newOrder", "1");
--- a/src-wad/src/org/openbravo/wad/javasource.xml	Fri Mar 04 13:04:56 2011 +0100
+++ b/src-wad/src/org/openbravo/wad/javasource.xml	Fri Mar 04 13:25:30 2011 +0100
@@ -37,6 +37,7 @@
   <PARAMETER id="windowName" name = "windowName" default=" "/>
   <PARAMETER id="key" name = "key" default=" "/>
   <PARAMETER id="keyParent" name = "keyParent" default=" "/>
+  <PARAMETER id="parentFieldID" name = "parentFieldID" default=""/>
   <PARAMETER id="keyParentT" name = "keyParentT" default=" "/>
   <PARAMETER id="keyParentSimple" name = "keyParentSimple" default=" "/>
   <PARAMETER id="parentTab" name = "parentTab" default=" "/>
--- a/src/org/openbravo/erpCommon/businessUtility/AuditTrailPopup_data.xsql	Fri Mar 04 13:04:56 2011 +0100
+++ b/src/org/openbravo/erpCommon/businessUtility/AuditTrailPopup_data.xsql	Fri Mar 04 13:25:30 2011 +0100
@@ -64,13 +64,14 @@
       <Field name="nametab" value="void"/>
       <Field name="editreference" value="void"/>
       <Field name="tabmodule" value="void"/>
+      <Field name="adFieldId" value="void"/>
   </SqlMethod>
 
 <!-- method from src-wad/src/org/openbravo/wad/Fields_data.xsql, both copies need to stay in sync -->
   <SqlMethod name="parentsColumnName" type="preparedStatement" return="multiple">
       <SqlMethodComment>Name of the columns parent of the tab</SqlMethodComment>
       <Sql><![CDATA[
-        SELECT ColumnName AS NAME, AD_REFERENCE_id AS reference, ad_reference_value_id AS referencevalue,
+        SELECT AD_FIELD.AD_FIELD_ID, ColumnName AS NAME, AD_REFERENCE_id AS reference, ad_reference_value_id AS referencevalue,
         (SELECT tableNAME FROM AD_TABLE, AD_TAB WHERE AD_TABLE.ad_table_id = AD_TAB.ad_table_id
         AND AD_TAB.ad_tab_id=?) AS tablename, ? as AD_Tab_ID, (select name from ad_tab where ad_tab_id = ?) as parent_tab_name,
         (SELECT P.ad_module_id FROM AD_TABLE T, AD_PACKAGE P WHERE T.ad_table_id = AD_COLUMN.ad_table_id AND T.AD_PACKAGE_ID = P.AD_PACKAGE_ID) as tableModule,
@@ -91,7 +92,7 @@
   <SqlMethod name="parentsColumnReal" type="preparedStatement" return="multiple">
       <SqlMethodComment>Name of the columns parent of the tab</SqlMethodComment>
       <Sql>
-        SELECT ColumnName AS NAME, AD_REFERENCE_id AS reference, ad_reference_value_id AS referencevalue,
+        SELECT AD_FIELD.AD_FIELD_ID, ColumnName AS NAME, AD_REFERENCE_id AS reference, ad_reference_value_id AS referencevalue,
         (SELECT tableNAME FROM AD_TABLE, AD_TAB WHERE AD_TABLE.ad_table_id = AD_TAB.ad_table_id
         AND AD_TAB.ad_tab_id=?) AS tablename,
         (SELECT P.ad_module_id FROM AD_TABLE T, AD_PACKAGE P WHERE T.ad_table_id = AD_COLUMN.ad_table_id AND T.AD_PACKAGE_ID = P.AD_PACKAGE_ID) as tableModule,
--- a/src/org/openbravo/erpCommon/utility/Utility.java	Fri Mar 04 13:04:56 2011 +0100
+++ b/src/org/openbravo/erpCommon/utility/Utility.java	Fri Mar 04 13:25:30 2011 +0100
@@ -2877,4 +2877,36 @@
       OBContext.restorePreviousMode();
     }
   }
+
+  /**
+   * Returns a field name in the specified language. If there is not translation for that language,
+   * it returns the base name of the field.
+   * 
+   * @param fieldId
+   *          ID of the field to look for.
+   * @param language
+   *          Langage to get the name in.
+   * @return field name in the correct language.
+   */
+  public static String getFieldName(String fieldId, String language) {
+    StringBuilder hql = new StringBuilder();
+    hql.append("select (select t.name\n");
+    hql.append("          from ADFieldTrl t\n");
+    hql.append("         where t.field = f\n");
+    hql.append("           and t.language.language=:lang),\n");
+    hql.append("       f.name\n");
+    hql.append("  from ADField f\n");
+    hql.append(" where f.id =:fieldId\n");
+    Query qName = OBDal.getInstance().getSession().createQuery(hql.toString());
+    qName.setParameter("lang", language);
+    qName.setParameter("fieldId", fieldId);
+
+    if (qName.list().isEmpty()) {
+      log4j.warn("Not found name for fieldId " + fieldId);
+      return "";
+    }
+
+    Object[] names = (Object[]) qName.list().get(0);
+    return names[0] != null ? (String) names[0] : (String) names[1];
+  }
 }