details:   https://code.openbravo.com/erp/devel/pi/rev/984e19080e17
changeset: 34479:984e19080e17
user:      Javier Armendáriz <javier.armendariz <at> openbravo.com>
date:      Wed Aug 01 13:42:45 2018 +0200
summary:   Fixed issue 38922: The variants of a product are not shown.

Currently the manage variants datasource is limited to 1000 variants, and
if this limit is exceeded no data is calculated even if performing filters.
This process needs further optimization and refactor.
This changeset adds the possibility of showing an error message when a exception
in the datasource is thrown. This let us to show a different message when
variants limit is exceeded or no variants are available.

diffstat:

 
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/process/ob-pick-and-execute-grid.js
 |   4 ++
 
modules/org.openbravo.service.datasource/src/org/openbravo/service/datasource/ReadOnlyDataSourceService.java
         |  10 ++--
 
modules/org.openbravo.userinterface.smartclient/web/org.openbravo.userinterface.smartclient/js/ob-smartclient.js
     |  18 ++++++++++
 src-db/database/sourcedata/AD_MESSAGE.xml                                      
                                      |  16 +++++++-
 src/org/openbravo/materialmgmt/ManageVariantsDS.java                           
                                      |   3 +-
 web/js/productCharacteristicsProcess.js                                        
                                      |   2 +-
 6 files changed, 44 insertions(+), 9 deletions(-)

diffs (135 lines):

diff -r 97100140eab3 -r 984e19080e17 
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/process/ob-pick-and-execute-grid.js
--- 
a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/process/ob-pick-and-execute-grid.js
      Thu Aug 02 13:19:02 2018 +0200
+++ 
b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/process/ob-pick-and-execute-grid.js
      Wed Aug 01 13:42:45 2018 +0200
@@ -659,6 +659,10 @@
     return this.data.localData[0] !== undefined;
   },
 
+  showMessage: function (type, messageKey) {
+    this.view.messageBar.setMessage(type, OB.I18N.getLabel(messageKey));
+  },
+
   dataArrived: function (startRow, endRow) {
     var record, i, rows, selectedLen = this.selectedIds.length,
         len, savedRecord, index, j, fields, allRequiredSet;
diff -r 97100140eab3 -r 984e19080e17 
modules/org.openbravo.service.datasource/src/org/openbravo/service/datasource/ReadOnlyDataSourceService.java
--- 
a/modules/org.openbravo.service.datasource/src/org/openbravo/service/datasource/ReadOnlyDataSourceService.java
      Thu Aug 02 13:19:02 2018 +0200
+++ 
b/modules/org.openbravo.service.datasource/src/org/openbravo/service/datasource/ReadOnlyDataSourceService.java
      Wed Aug 01 13:42:45 2018 +0200
@@ -70,12 +70,12 @@
     }
     boolean preventCountOperation = 
"true".equals(parameters.get(JsonConstants.NOCOUNT_PARAMETER));
 
-    List<JSONObject> jsonObjects = fetchJSONObject(parameters);
-    if (parameters.get(NEW_END_ROW) != null) {
-      newEndRow = Integer.parseInt(parameters.get(NEW_END_ROW));
-    }
-    // now jsonfy the data
     try {
+      List<JSONObject> jsonObjects = fetchJSONObject(parameters);
+      if (parameters.get(NEW_END_ROW) != null) {
+        newEndRow = Integer.parseInt(parameters.get(NEW_END_ROW));
+      }
+      // now jsonfy the data
       final JSONObject jsonResult = new JSONObject();
       final JSONObject jsonResponse = new JSONObject();
       jsonResponse.put(JsonConstants.RESPONSE_STATUS, 
JsonConstants.RPCREQUEST_STATUS_SUCCESS);
diff -r 97100140eab3 -r 984e19080e17 
modules/org.openbravo.userinterface.smartclient/web/org.openbravo.userinterface.smartclient/js/ob-smartclient.js
--- 
a/modules/org.openbravo.userinterface.smartclient/web/org.openbravo.userinterface.smartclient/js/ob-smartclient.js
  Thu Aug 02 13:19:02 2018 +0200
+++ 
b/modules/org.openbravo.userinterface.smartclient/web/org.openbravo.userinterface.smartclient/js/ob-smartclient.js
  Wed Aug 01 13:42:45 2018 +0200
@@ -775,6 +775,13 @@
       target.view.toolBar.updateButtonState();
     }
 
+    if (response.status === -4 && target && target.showMessage) {
+      var errorMessage = this.parseErrorMessage(response);
+      if (errorMessage) {
+        target.showMessage(isc.OBMessageBar.TYPE_ERROR, errorMessage);
+      }
+    }
+
     // in case of response timeout, show the error in the view if possible
     if (this.isServerTimeoutResponse(response) && 
this.canShowErrorMessage(target)) {
       target.view.setErrorMessageFromResponse(response, response.data, 
request);
@@ -785,6 +792,17 @@
     }
   },
 
+  parseErrorMessage: function(response) {
+    if (response.httpResponseText) {
+      var jsonResponse = JSON.parse(response.httpResponseText);
+      if (jsonResponse.response && jsonResponse.response.error && 
jsonResponse.response.error.message) {
+        return jsonResponse.response.error.message;
+      }
+    }
+
+    return null;
+  },
+
   isServerTimeoutResponse: function (response) {
     return response.status === isc.RPCResponse.STATUS_SERVER_TIMEOUT;
   },
diff -r 97100140eab3 -r 984e19080e17 src-db/database/sourcedata/AD_MESSAGE.xml
--- a/src-db/database/sourcedata/AD_MESSAGE.xml Thu Aug 02 13:19:02 2018 +0200
+++ b/src-db/database/sourcedata/AD_MESSAGE.xml Wed Aug 01 13:42:45 2018 +0200
@@ -17209,6 +17209,18 @@
 <!--1D2905EAB15A4DB0B794BF8DC11F2678-->  
<ISINCLUDEINI18N><![CDATA[N]]></ISINCLUDEINI18N>
 <!--1D2905EAB15A4DB0B794BF8DC11F2678--></AD_MESSAGE>
 
+<!--1D5A2A3E2D1A4A91AE3F9C11D3DAEABA--><AD_MESSAGE>
+<!--1D5A2A3E2D1A4A91AE3F9C11D3DAEABA-->  
<AD_MESSAGE_ID><![CDATA[1D5A2A3E2D1A4A91AE3F9C11D3DAEABA]]></AD_MESSAGE_ID>
+<!--1D5A2A3E2D1A4A91AE3F9C11D3DAEABA-->  
<AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--1D5A2A3E2D1A4A91AE3F9C11D3DAEABA-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--1D5A2A3E2D1A4A91AE3F9C11D3DAEABA-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--1D5A2A3E2D1A4A91AE3F9C11D3DAEABA-->  <VALUE><![CDATA[NoVariants]]></VALUE>
+<!--1D5A2A3E2D1A4A91AE3F9C11D3DAEABA-->  <MSGTEXT><![CDATA[There are no 
product variants. Please add some product characteristics.]]></MSGTEXT>
+<!--1D5A2A3E2D1A4A91AE3F9C11D3DAEABA-->  <MSGTYPE><![CDATA[I]]></MSGTYPE>
+<!--1D5A2A3E2D1A4A91AE3F9C11D3DAEABA-->  
<AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
+<!--1D5A2A3E2D1A4A91AE3F9C11D3DAEABA-->  
<ISINCLUDEINI18N><![CDATA[Y]]></ISINCLUDEINI18N>
+<!--1D5A2A3E2D1A4A91AE3F9C11D3DAEABA--></AD_MESSAGE>
+
 <!--1D5D2925CB05481485FA38B582B0DD28--><AD_MESSAGE>
 <!--1D5D2925CB05481485FA38B582B0DD28-->  
<AD_MESSAGE_ID><![CDATA[1D5D2925CB05481485FA38B582B0DD28]]></AD_MESSAGE_ID>
 <!--1D5D2925CB05481485FA38B582B0DD28-->  
<AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
@@ -23919,8 +23931,8 @@
 <!--A0844A1983A54B4AB60640B28B66C2B2-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
 <!--A0844A1983A54B4AB60640B28B66C2B2-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
 <!--A0844A1983A54B4AB60640B28B66C2B2-->  <VALUE><![CDATA[HighRecords]]></VALUE>
-<!--A0844A1983A54B4AB60640B28B66C2B2-->  <MSGTEXT><![CDATA[The number of 
records is too high. Please, try to review product characteristics.]]></MSGTEXT>
-<!--A0844A1983A54B4AB60640B28B66C2B2-->  <MSGTYPE><![CDATA[I]]></MSGTYPE>
+<!--A0844A1983A54B4AB60640B28B66C2B2-->  <MSGTEXT><![CDATA[The number of 
records is too high. Please, try to review and reduce the number of product 
characteristics.]]></MSGTEXT>
+<!--A0844A1983A54B4AB60640B28B66C2B2-->  <MSGTYPE><![CDATA[E]]></MSGTYPE>
 <!--A0844A1983A54B4AB60640B28B66C2B2-->  
<AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
 <!--A0844A1983A54B4AB60640B28B66C2B2-->  
<ISINCLUDEINI18N><![CDATA[Y]]></ISINCLUDEINI18N>
 <!--A0844A1983A54B4AB60640B28B66C2B2--></AD_MESSAGE>
diff -r 97100140eab3 -r 984e19080e17 
src/org/openbravo/materialmgmt/ManageVariantsDS.java
--- a/src/org/openbravo/materialmgmt/ManageVariantsDS.java      Thu Aug 02 
13:19:02 2018 +0200
+++ b/src/org/openbravo/materialmgmt/ManageVariantsDS.java      Wed Aug 01 
13:42:45 2018 +0200
@@ -32,6 +32,7 @@
 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.base.exception.OBSecurityException;
 import org.openbravo.base.model.Entity;
 import org.openbravo.base.model.ModelProvider;
@@ -146,7 +147,7 @@
       }
 
       if (variantNumber > 1000) {
-        return result;
+        throw new OBException("HighRecords");
       }
       totalMaxLength += Long.toString(variantNumber).length();
       boolean useCodes = totalMaxLength <= searchKeyLength;
diff -r 97100140eab3 -r 984e19080e17 web/js/productCharacteristicsProcess.js
--- a/web/js/productCharacteristicsProcess.js   Thu Aug 02 13:19:02 2018 +0200
+++ b/web/js/productCharacteristicsProcess.js   Wed Aug 01 13:42:45 2018 +0200
@@ -58,7 +58,7 @@
     var nRecordsReceived = grid.getData().getLength(),
         messageBar = grid.view.messageBar;
     if (nRecordsReceived == 0) {
-      messageBar.setMessage('info', OB.I18N.getLabel('HighRecords'));
+      messageBar.setMessage(isc.OBMessageBar.TYPE_INFO, 
OB.I18N.getLabel('NoVariants'));
     }
   },
 };

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Openbravo-commits mailing list
Openbravo-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to