Fixes issue 27489 Fixes issue 27490 Show product characteristics hierarchy dropdown in the button of
authorRafa de Miguel <rafael.demiguel@openbravo.com>
Wed, 27 Aug 2014 14:39:48 +0200
changeset 24347 9afa505ca5af
parent 24346 6701e443c05a
child 24348 3a731d082a0d
child 24349 ab00fd374519
Fixes issue 27489 Fixes issue 27490 Show product characteristics hierarchy dropdown in the button of
“Update characteristics” within Product window. AND Display in product form view hierarchy of
the characteristics and the description just for one level
modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/reference/CharacteristicsUIDefinition.java
src-db/database/sourcedata/AD_REFERENCE.xml
src-db/database/sourcedata/AD_REF_LIST.xml
src-db/database/sourcedata/AD_REF_TREE.xml
src-db/database/sourcedata/AD_REF_TREE_FIELD.xml
web/js/productCharacteristicsProcess.js
--- a/modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/reference/CharacteristicsUIDefinition.java	Wed Aug 27 17:18:58 2014 +0000
+++ b/modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/reference/CharacteristicsUIDefinition.java	Wed Aug 27 14:39:48 2014 +0200
@@ -19,20 +19,31 @@
 
 package org.openbravo.client.kernel.reference;
 
+import java.util.List;
+
 import org.apache.commons.lang.StringUtils;
+import org.apache.log4j.Logger;
 import org.codehaus.jettison.json.JSONException;
 import org.codehaus.jettison.json.JSONObject;
+import org.hibernate.criterion.Restrictions;
 import org.openbravo.base.exception.OBException;
 import org.openbravo.client.kernel.RequestContext;
 import org.openbravo.dal.core.OBContext;
+import org.openbravo.dal.service.OBCriteria;
 import org.openbravo.dal.service.OBDal;
 import org.openbravo.data.Sqlc;
+import org.openbravo.erpCommon.businessUtility.Preferences;
 import org.openbravo.model.ad.ui.Field;
+import org.openbravo.model.ad.utility.Tree;
+import org.openbravo.model.ad.utility.TreeNode;
+import org.openbravo.model.common.plm.CharacteristicValue;
 import org.openbravo.model.common.plm.Product;
 import org.openbravo.model.common.plm.ProductCharacteristicValue;
 
 public class CharacteristicsUIDefinition extends TextUIDefinition {
 
+  private static final Logger log4j = Logger.getLogger(CharacteristicsUIDefinition.class);
+
   @Override
   public String getFormEditorType() {
     return "OBCharacteristicsItem";
@@ -75,8 +86,8 @@
 
       JSONObject jsonValue = new JSONObject();
       for (ProductCharacteristicValue charValue : product.getProductCharacteristicValueList()) {
-        jsonValue.put(charValue.getCharacteristic().getIdentifier(), charValue
-            .getCharacteristicValue().getIdentifier());
+        jsonValue.put(charValue.getCharacteristic().getIdentifier(),
+            getValue(charValue.getCharacteristicValue()));
       }
 
       value.put("characteristics", jsonValue);
@@ -91,4 +102,52 @@
     }
   }
 
+  private String getValue(CharacteristicValue characValue) {
+    int levels = 0;
+
+    try {
+      String levelsPreference = Preferences.getPreferenceValue("ShowProductCharacteristicsParents",
+          true, OBContext.getOBContext().getCurrentClient(), OBContext.getOBContext()
+              .getCurrentOrganization(), OBContext.getOBContext().getUser(), OBContext
+              .getOBContext().getRole(), null);
+      levels = Integer.parseInt(levelsPreference);
+    } catch (Exception e) {
+      if (e instanceof NumberFormatException) {
+        log4j.error("ShowProductCharacteristicsParents preference is not a number", e);
+      } else {
+        log4j.error("Error finding ShowProductCharacteristicsParents preference", e);
+      }
+    }
+
+    String value = characValue.getIdentifier();
+    if (levels > 0) {
+      CharacteristicValue currentCharValue = characValue;
+      int i = 0;
+      boolean existsParent = true;
+
+      while (i < levels && existsParent) {
+        existsParent = false;
+        // Find parent
+        OBCriteria<TreeNode> treeNodeCri = OBDal.getInstance().createCriteria(TreeNode.class);
+        treeNodeCri.createAlias(TreeNode.PROPERTY_TREE, "tree");
+        treeNodeCri.add(Restrictions.eq("tree." + Tree.PROPERTY_CLIENT, OBContext.getOBContext()
+            .getCurrentClient()));
+        treeNodeCri.add(Restrictions.eq("tree." + Tree.PROPERTY_TYPEAREA, "CH"));
+        treeNodeCri.add(Restrictions.eq(TreeNode.PROPERTY_NODE, currentCharValue.getId()));
+        List<TreeNode> treeNodeList = treeNodeCri.list();
+        if (treeNodeList.size() == 1 && !treeNodeList.get(0).getReportSet().equals("0")) {
+          // Parent Exists
+          currentCharValue = OBDal.getInstance().get(CharacteristicValue.class,
+              treeNodeList.get(0).getReportSet());
+          value = currentCharValue.getIdentifier() + " / " + value;
+          existsParent = true;
+        }
+        i++;
+      }
+
+    }
+
+    return value;
+  }
+
 }
--- a/src-db/database/sourcedata/AD_REFERENCE.xml	Wed Aug 27 17:18:58 2014 +0000
+++ b/src-db/database/sourcedata/AD_REFERENCE.xml	Wed Aug 27 14:39:48 2014 +0200
@@ -6158,6 +6158,18 @@
 <!--D2D4CC1F12434BB69733166A9423F2C6-->  <ISVALUEDISPLAYED><![CDATA[N]]></ISVALUEDISPLAYED>
 <!--D2D4CC1F12434BB69733166A9423F2C6--></AD_REFERENCE>
 
+<!--D3D9A7BAF4594950922A22B2D7ABFA74--><AD_REFERENCE>
+<!--D3D9A7BAF4594950922A22B2D7ABFA74-->  <AD_REFERENCE_ID><![CDATA[D3D9A7BAF4594950922A22B2D7ABFA74]]></AD_REFERENCE_ID>
+<!--D3D9A7BAF4594950922A22B2D7ABFA74-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--D3D9A7BAF4594950922A22B2D7ABFA74-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--D3D9A7BAF4594950922A22B2D7ABFA74-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--D3D9A7BAF4594950922A22B2D7ABFA74-->  <NAME><![CDATA[Characteristic Selector]]></NAME>
+<!--D3D9A7BAF4594950922A22B2D7ABFA74-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
+<!--D3D9A7BAF4594950922A22B2D7ABFA74-->  <ISBASEREFERENCE><![CDATA[N]]></ISBASEREFERENCE>
+<!--D3D9A7BAF4594950922A22B2D7ABFA74-->  <PARENTREFERENCE_ID><![CDATA[8C57A4A2E05F4261A1FADF47C30398AD]]></PARENTREFERENCE_ID>
+<!--D3D9A7BAF4594950922A22B2D7ABFA74-->  <ISVALUEDISPLAYED><![CDATA[N]]></ISVALUEDISPLAYED>
+<!--D3D9A7BAF4594950922A22B2D7ABFA74--></AD_REFERENCE>
+
 <!--D61E6D984E214F99B10DE56395ED692B--><AD_REFERENCE>
 <!--D61E6D984E214F99B10DE56395ED692B-->  <AD_REFERENCE_ID><![CDATA[D61E6D984E214F99B10DE56395ED692B]]></AD_REFERENCE_ID>
 <!--D61E6D984E214F99B10DE56395ED692B-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
--- a/src-db/database/sourcedata/AD_REF_LIST.xml	Wed Aug 27 17:18:58 2014 +0000
+++ b/src-db/database/sourcedata/AD_REF_LIST.xml	Wed Aug 27 14:39:48 2014 +0200
@@ -9906,6 +9906,17 @@
 <!--7CF20E12800D4B54A493CE90C90F767B-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
 <!--7CF20E12800D4B54A493CE90C90F767B--></AD_REF_LIST>
 
+<!--7CF3A173FBDC4078B627C04BA748B8E9--><AD_REF_LIST>
+<!--7CF3A173FBDC4078B627C04BA748B8E9-->  <AD_REF_LIST_ID><![CDATA[7CF3A173FBDC4078B627C04BA748B8E9]]></AD_REF_LIST_ID>
+<!--7CF3A173FBDC4078B627C04BA748B8E9-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--7CF3A173FBDC4078B627C04BA748B8E9-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--7CF3A173FBDC4078B627C04BA748B8E9-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--7CF3A173FBDC4078B627C04BA748B8E9-->  <VALUE><![CDATA[ShowProductCharacteristicsParents]]></VALUE>
+<!--7CF3A173FBDC4078B627C04BA748B8E9-->  <NAME><![CDATA[Show Product Characteristics Parents]]></NAME>
+<!--7CF3A173FBDC4078B627C04BA748B8E9-->  <AD_REFERENCE_ID><![CDATA[A26BA480E2014707B47257024C3CBFF7]]></AD_REFERENCE_ID>
+<!--7CF3A173FBDC4078B627C04BA748B8E9-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
+<!--7CF3A173FBDC4078B627C04BA748B8E9--></AD_REF_LIST>
+
 <!--7D10DB31B24A4ACAA68FAB36DA3F82FB--><AD_REF_LIST>
 <!--7D10DB31B24A4ACAA68FAB36DA3F82FB-->  <AD_REF_LIST_ID><![CDATA[7D10DB31B24A4ACAA68FAB36DA3F82FB]]></AD_REF_LIST_ID>
 <!--7D10DB31B24A4ACAA68FAB36DA3F82FB-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src-db/database/sourcedata/AD_REF_TREE.xml	Wed Aug 27 14:39:48 2014 +0200
@@ -0,0 +1,17 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<data>
+<!--95582A51651D415993D0FD3B64C8E861--><AD_REF_TREE>
+<!--95582A51651D415993D0FD3B64C8E861-->  <AD_REF_TREE_ID><![CDATA[95582A51651D415993D0FD3B64C8E861]]></AD_REF_TREE_ID>
+<!--95582A51651D415993D0FD3B64C8E861-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--95582A51651D415993D0FD3B64C8E861-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--95582A51651D415993D0FD3B64C8E861-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--95582A51651D415993D0FD3B64C8E861-->  <AD_REFERENCE_ID><![CDATA[D3D9A7BAF4594950922A22B2D7ABFA74]]></AD_REFERENCE_ID>
+<!--95582A51651D415993D0FD3B64C8E861-->  <AD_TABLE_ID><![CDATA[E913D17C9B3847CF92235082DBE2EC44]]></AD_TABLE_ID>
+<!--95582A51651D415993D0FD3B64C8E861-->  <WHERECLAUSE><![CDATA[e.characteristic.id=@parentCharId@]]></WHERECLAUSE>
+<!--95582A51651D415993D0FD3B64C8E861-->  <VALUEFIELD_ID><![CDATA[7B82AF2B5C2C48CDB05C78BA3DC26989]]></VALUEFIELD_ID>
+<!--95582A51651D415993D0FD3B64C8E861-->  <DISPLAYFIELD_ID><![CDATA[01982CD5659A4E76A0781FBE4FA3CFC7]]></DISPLAYFIELD_ID>
+<!--95582A51651D415993D0FD3B64C8E861-->  <AD_TABLE_TREE_ID><![CDATA[B6C7204712CC4EDEB5705C93F706DF05]]></AD_TABLE_TREE_ID>
+<!--95582A51651D415993D0FD3B64C8E861-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
+<!--95582A51651D415993D0FD3B64C8E861--></AD_REF_TREE>
+
+</data>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src-db/database/sourcedata/AD_REF_TREE_FIELD.xml	Wed Aug 27 14:39:48 2014 +0200
@@ -0,0 +1,39 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<data>
+<!--01982CD5659A4E76A0781FBE4FA3CFC7--><AD_REF_TREE_FIELD>
+<!--01982CD5659A4E76A0781FBE4FA3CFC7-->  <AD_REF_TREE_FIELD_ID><![CDATA[01982CD5659A4E76A0781FBE4FA3CFC7]]></AD_REF_TREE_FIELD_ID>
+<!--01982CD5659A4E76A0781FBE4FA3CFC7-->  <AD_REF_TREE_ID><![CDATA[95582A51651D415993D0FD3B64C8E861]]></AD_REF_TREE_ID>
+<!--01982CD5659A4E76A0781FBE4FA3CFC7-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--01982CD5659A4E76A0781FBE4FA3CFC7-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--01982CD5659A4E76A0781FBE4FA3CFC7-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
+<!--01982CD5659A4E76A0781FBE4FA3CFC7-->  <NAME><![CDATA[name]]></NAME>
+<!--01982CD5659A4E76A0781FBE4FA3CFC7-->  <PROPERTY><![CDATA[name]]></PROPERTY>
+<!--01982CD5659A4E76A0781FBE4FA3CFC7-->  <ISCENTRALLYMAINTAINED><![CDATA[Y]]></ISCENTRALLYMAINTAINED>
+<!--01982CD5659A4E76A0781FBE4FA3CFC7-->  <SORT><![CDATA[N]]></SORT>
+<!--01982CD5659A4E76A0781FBE4FA3CFC7-->  <FILTER><![CDATA[Y]]></FILTER>
+<!--01982CD5659A4E76A0781FBE4FA3CFC7-->  <SEARCHINSUGGESTIONBOX><![CDATA[N]]></SEARCHINSUGGESTIONBOX>
+<!--01982CD5659A4E76A0781FBE4FA3CFC7-->  <SHOWINGRID><![CDATA[Y]]></SHOWINGRID>
+<!--01982CD5659A4E76A0781FBE4FA3CFC7-->  <SORTNO><![CDATA[0]]></SORTNO>
+<!--01982CD5659A4E76A0781FBE4FA3CFC7-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--01982CD5659A4E76A0781FBE4FA3CFC7-->  <SHOWINPICKLIST><![CDATA[Y]]></SHOWINPICKLIST>
+<!--01982CD5659A4E76A0781FBE4FA3CFC7--></AD_REF_TREE_FIELD>
+
+<!--7B82AF2B5C2C48CDB05C78BA3DC26989--><AD_REF_TREE_FIELD>
+<!--7B82AF2B5C2C48CDB05C78BA3DC26989-->  <AD_REF_TREE_FIELD_ID><![CDATA[7B82AF2B5C2C48CDB05C78BA3DC26989]]></AD_REF_TREE_FIELD_ID>
+<!--7B82AF2B5C2C48CDB05C78BA3DC26989-->  <AD_REF_TREE_ID><![CDATA[95582A51651D415993D0FD3B64C8E861]]></AD_REF_TREE_ID>
+<!--7B82AF2B5C2C48CDB05C78BA3DC26989-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--7B82AF2B5C2C48CDB05C78BA3DC26989-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--7B82AF2B5C2C48CDB05C78BA3DC26989-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
+<!--7B82AF2B5C2C48CDB05C78BA3DC26989-->  <NAME><![CDATA[ID]]></NAME>
+<!--7B82AF2B5C2C48CDB05C78BA3DC26989-->  <PROPERTY><![CDATA[id]]></PROPERTY>
+<!--7B82AF2B5C2C48CDB05C78BA3DC26989-->  <ISCENTRALLYMAINTAINED><![CDATA[Y]]></ISCENTRALLYMAINTAINED>
+<!--7B82AF2B5C2C48CDB05C78BA3DC26989-->  <SORT><![CDATA[N]]></SORT>
+<!--7B82AF2B5C2C48CDB05C78BA3DC26989-->  <FILTER><![CDATA[N]]></FILTER>
+<!--7B82AF2B5C2C48CDB05C78BA3DC26989-->  <SEARCHINSUGGESTIONBOX><![CDATA[N]]></SEARCHINSUGGESTIONBOX>
+<!--7B82AF2B5C2C48CDB05C78BA3DC26989-->  <SHOWINGRID><![CDATA[N]]></SHOWINGRID>
+<!--7B82AF2B5C2C48CDB05C78BA3DC26989-->  <SORTNO><![CDATA[0]]></SORTNO>
+<!--7B82AF2B5C2C48CDB05C78BA3DC26989-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--7B82AF2B5C2C48CDB05C78BA3DC26989-->  <SHOWINPICKLIST><![CDATA[N]]></SHOWINPICKLIST>
+<!--7B82AF2B5C2C48CDB05C78BA3DC26989--></AD_REF_TREE_FIELD>
+
+</data>
--- a/web/js/productCharacteristicsProcess.js	Wed Aug 27 17:18:58 2014 +0000
+++ b/web/js/productCharacteristicsProcess.js	Wed Aug 27 14:39:48 2014 +0200
@@ -51,16 +51,16 @@
     params.action = 'INITIALIZE';
     OB.ProductCharacteristics.execute(params, view);
   },
-  
+
   //Shows a message in order to notify that number of records is too high, so
   //product characteristics should be changed.
-  testOnGridLoad: function(grid) {
-	    var nRecordsReceived = grid.getData().getLength(),
-	        messageBar = grid.view.messageBar;
-	    if (nRecordsReceived == 0) {
-	        messageBar.setMessage('info', OB.I18N.getLabel('HighRecords'));
-	    }
-	},
+  testOnGridLoad: function (grid) {
+    var nRecordsReceived = grid.getData().getLength(),
+        messageBar = grid.view.messageBar;
+    if (nRecordsReceived == 0) {
+      messageBar.setMessage('info', OB.I18N.getLabel('HighRecords'));
+    }
+  },
 };
 
 isc.defineClass('UpdateInvariantCharacteristicsPopup', isc.OBPopup);
@@ -85,12 +85,111 @@
     OB.TestRegistry.register('org.openbravo.client.application.UpdateInvariantCharacteristics.popup', this);
     var originalView = this.view,
         params = this.params,
-        i;
-   
+        i, emptyFunction, initTreeField;
+
+    emptyFunction = function () {};
+    initTreeField = function () {
+      this.optionDataSource = OB.Datasource.create({
+        createClassName: '',
+        dataURL: '/openbravo/org.openbravo.service.datasource/CharacteristicValue',
+        requestProperties: {
+          params: {
+            targetProperty: this.name,
+            adTabId: 'A43B5CFC17754AED86B9E57F71460C4E',
+            IsSelectorItem: 'true',
+            Constants_FIELDSEPARATOR: '$',
+            columnName: this.name,
+            Constants_IDENTIFIER: '_identifier',
+            _extraProperties: 'id,name'
+          }
+        },
+        fields: [{
+          name: 'id',
+          type: '_id_13',
+          primaryKey: true
+        }, {
+          name: 'client',
+          type: '_id_19'
+        }, {
+          name: 'client$_identifier'
+        }, {
+          name: 'organization',
+          type: '_id_19'
+        }, {
+          name: 'organization$_identifier'
+        }, {
+          name: 'active',
+          type: '_id_20'
+        }, {
+          name: 'creationDate',
+          type: '_id_16'
+        }, {
+          name: 'createdBy',
+          type: '_id_30'
+        }, {
+          name: 'createdBy$_identifier'
+        }, {
+          name: 'updated',
+          type: '_id_16'
+        }, {
+          name: 'updatedBy',
+          type: '_id_30'
+        }, {
+          name: 'updatedBy$_identifier'
+        }, {
+          name: 'characteristic',
+          type: '_id_19'
+        }, {
+          name: 'characteristic$_identifier'
+        }, {
+          name: 'name',
+          type: '_id_10'
+        }, {
+          name: 'summaryLevel',
+          type: '_id_20'
+        }, {
+          name: 'code',
+          type: '_id_10'
+        }, {
+          name: 'description',
+          type: '_id_10'
+        }, {
+          name: 'addProducts',
+          type: '_id_28'
+        }, {
+          name: 'id',
+          type: '_id_13',
+          additional: true,
+          primaryKey: true
+        }, {
+          name: 'name',
+          type: '_id_10',
+          additional: true
+        }]
+      });
+
+      this.Super('init', arguments);
+
+      // Place the picklist to the front
+      this.Super('init', arguments);
+      this.tree.originalShow = this.tree.show;
+      this.tree.treeItem.addParamsToRequest = function () {
+        return {
+          parentCharId: this.parentCharId
+        }
+      };
+      this.tree.show = function () {
+        this.originalShow();
+        this.bringToFront();
+      };
+    };
+
     // Populates the combos using the provided characteristicList
     this.characteristicCombos = [];
     for (i = 0; i < this.characteristicList.length; i++) {
       this.characteristicCombos[i] = isc.DynamicForm.create({
+        view: originalView.view,
+        handleItemChange: emptyFunction,
         fields: [{
           id: this.characteristicList[i].id,
           name: this.characteristicList[i].name,
@@ -101,7 +200,46 @@
           height: 20,
           width: 255,
           required: false,
-          type: '_id_17'
+          form: {
+            view: originalView.view
+          },
+          columnName: this.characteristicList[i].name,
+          inpColumnName: this.characteristicList[i].name,
+          refColumnName: this.characteristicList[i].name,
+          targetEntity: this.characteristicList[i].name,
+          treeReferenceId: '95582A51651D415993D0FD3B64C8E861',
+          parentCharId: this.characteristicList[i].id,
+          dataSourceId: '90034CAE96E847D78FBEF6D38CB1930D',
+          parentSelectionAllowed: true,
+          popupTextMatchStyle: 'substring',
+          textMatchStyle: 'substring',
+          defaultPopupFilterField: 'name',
+          displayField: 'name',
+          valueField: 'id',
+          referencedTableId: 'E913D17C9B3847CF92235082DBE2EC44',
+          pickListFields: [{
+            title: ' ',
+            name: 'name',
+            type: 'text'
+          }],
+          showSelectorGrid: true,
+          treeGridFields: [{
+            title: 'name',
+            name: 'name',
+            canSort: false,
+            type: '_id_10'
+          }],
+          extraSearchFields: [],
+          init: initTreeField,
+          gridProps: {
+            sort: 3,
+            autoExpand: true,
+            displayField: 'characteristicValue$name',
+            displaylength: 32,
+            fkField: true,
+            showHover: true
+          },
+          type: '_id_D3D9A7BAF4594950922A22B2D7ABFA74'
         }]
       });
     }
@@ -175,4 +313,4 @@
     this.Super('initWidget', arguments);
   }
 
-});
+});
\ No newline at end of file