[view] pi merge
authorAsier Lostalé <asier.lostale@openbravo.com>
Mon, 06 Aug 2018 08:59:19 +0200
changeset 35066 ca52c98e1149
parent 35065 81d914aee0e4 (current diff)
parent 34479 984e19080e17 (diff)
child 35067 bbdf0c84c3e2
[view] pi merge
--- a/modules/org.openbravo.client.application/src/org/openbravo/client/application/report/BaseReportActionHandler.java	Fri Aug 03 16:29:18 2018 +0200
+++ b/modules/org.openbravo.client.application/src/org/openbravo/client/application/report/BaseReportActionHandler.java	Mon Aug 06 08:59:19 2018 +0200
@@ -69,6 +69,7 @@
 import org.openbravo.database.ConnectionProvider;
 import org.openbravo.database.SessionInfo;
 import org.openbravo.erpCommon.utility.OBMessageUtils;
+import org.openbravo.service.db.DbUtility;
 import org.openbravo.userinterface.selector.reference.FKMultiSelectorUIDefinition;
 import org.openbravo.utils.FileUtility;
 import org.slf4j.Logger;
@@ -130,11 +131,12 @@
       return result;
     } catch (Exception e) {
       log.error("Error generating report id: {}", parameters.get("reportId"), e);
+      Throwable uiException = DbUtility.getUnderlyingSQLException(e);
       return getResponseBuilder()
           .retryExecution()
           .showResultsInProcessView()
           .showMsgInProcessView(MessageType.ERROR,
-              OBMessageUtils.translateError(e.getMessage()).getMessage()).build();
+              OBMessageUtils.translateError(uiException.getMessage()).getMessage()).build();
     }
   }
 
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/process/ob-pick-and-execute-grid.js	Fri Aug 03 16:29:18 2018 +0200
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/process/ob-pick-and-execute-grid.js	Mon Aug 06 08:59:19 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;
--- a/modules/org.openbravo.service.datasource/src/org/openbravo/service/datasource/ReadOnlyDataSourceService.java	Fri Aug 03 16:29:18 2018 +0200
+++ b/modules/org.openbravo.service.datasource/src/org/openbravo/service/datasource/ReadOnlyDataSourceService.java	Mon Aug 06 08:59:19 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);
--- a/modules/org.openbravo.userinterface.smartclient/web/org.openbravo.userinterface.smartclient/js/ob-smartclient.js	Fri Aug 03 16:29:18 2018 +0200
+++ b/modules/org.openbravo.userinterface.smartclient/web/org.openbravo.userinterface.smartclient/js/ob-smartclient.js	Mon Aug 06 08:59:19 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;
   },
--- a/src-db/database/sourcedata/AD_MESSAGE.xml	Fri Aug 03 16:29:18 2018 +0200
+++ b/src-db/database/sourcedata/AD_MESSAGE.xml	Mon Aug 06 08:59:19 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>
--- a/src-test/src/org/openbravo/test/AllAntTaskTests.java	Fri Aug 03 16:29:18 2018 +0200
+++ b/src-test/src/org/openbravo/test/AllAntTaskTests.java	Mon Aug 06 08:59:19 2018 +0200
@@ -106,6 +106,7 @@
 import org.openbravo.test.services.ServicesTest2;
 import org.openbravo.test.services.ServicesTest3;
 import org.openbravo.test.system.CryptoUtilities;
+import org.openbravo.test.system.ErrorTextParserIntegrationTest;
 import org.openbravo.test.system.ErrorTextParserTest;
 import org.openbravo.test.system.ImportEntrySizeTest;
 import org.openbravo.test.system.Issue29934Test;
@@ -197,6 +198,7 @@
     SystemServiceTest.class, //
     SystemValidatorTest.class, //
     ErrorTextParserTest.class, //
+    ErrorTextParserIntegrationTest.class, //
     TestInfrastructure.class, //
     Issue29934Test.class, //
     ImportEntrySizeTest.class, //
--- a/src-test/src/org/openbravo/test/AllQuickAntTaskTests.java	Fri Aug 03 16:29:18 2018 +0200
+++ b/src-test/src/org/openbravo/test/AllQuickAntTaskTests.java	Mon Aug 06 08:59:19 2018 +0200
@@ -41,6 +41,7 @@
 import org.openbravo.test.security.OBContextCollectionsTest;
 import org.openbravo.test.security.PasswordStrengthCheckerTest;
 import org.openbravo.test.security.WritableReadableOrganizationClientTest;
+import org.openbravo.test.system.ErrorTextParserIntegrationTest;
 import org.openbravo.test.system.ErrorTextParserTest;
 import org.openbravo.test.system.ImportEntrySizeTest;
 import org.openbravo.test.system.Issue29934Test;
@@ -98,6 +99,7 @@
     SystemServiceTest.class, //
     SystemValidatorTest.class, //
     ErrorTextParserTest.class, //
+    ErrorTextParserIntegrationTest.class, //
     TestInfrastructure.class, //
     Issue29934Test.class, //
     ImportEntrySizeTest.class, //
--- a/src-test/src/org/openbravo/test/AntTaskTests.java	Fri Aug 03 16:29:18 2018 +0200
+++ b/src-test/src/org/openbravo/test/AntTaskTests.java	Mon Aug 06 08:59:19 2018 +0200
@@ -58,6 +58,7 @@
 import org.openbravo.test.security.OBContextCollectionsTest;
 import org.openbravo.test.security.PasswordStrengthCheckerTest;
 import org.openbravo.test.security.WritableReadableOrganizationClientTest;
+import org.openbravo.test.system.ErrorTextParserIntegrationTest;
 import org.openbravo.test.system.ErrorTextParserTest;
 import org.openbravo.test.system.ImportEntrySizeTest;
 import org.openbravo.test.system.Issue29934Test;
@@ -133,6 +134,7 @@
     SystemServiceTest.class, //
     SystemValidatorTest.class, //
     ErrorTextParserTest.class, //
+    ErrorTextParserIntegrationTest.class, //
     TestInfrastructure.class, //
     Issue29934Test.class, //
     ImportEntrySizeTest.class, //
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src-test/src/org/openbravo/test/system/ErrorTextParserIntegrationTest.java	Mon Aug 06 08:59:19 2018 +0200
@@ -0,0 +1,199 @@
+/*
+ *************************************************************************
+ * The contents of this file are subject to the Openbravo  Public  License
+ * Version  1.1  (the  "License"),  being   the  Mozilla   Public  License
+ * Version 1.1  with a permitted attribution clause; you may not  use this
+ * file except in compliance with the License. You  may  obtain  a copy of
+ * the License at http://www.openbravo.com/legal/license.html 
+ * Software distributed under the License  is  distributed  on  an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific  language  governing  rights  and  limitations
+ * under the License. 
+ * The Original Code is Openbravo ERP. 
+ * The Initial Developer of the Original Code is Openbravo SLU
+ * All portions are Copyright (C) 2010-2018 Openbravo SLU
+ * All Rights Reserved. 
+ * Contributor(s):  ______________________________________.
+ ************************************************************************
+ */
+
+package org.openbravo.test.system;
+
+import static org.hamcrest.CoreMatchers.containsString;
+import static org.hamcrest.CoreMatchers.not;
+import static org.hamcrest.Matchers.hasItem;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThat;
+
+import java.sql.Connection;
+
+import javax.servlet.ServletException;
+
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.junit.Test;
+import org.openbravo.base.secureApp.VariablesSecureApp;
+import org.openbravo.database.ConnectionProvider;
+import org.openbravo.erpCommon.utility.OBError;
+import org.openbravo.erpCommon.utility.Utility;
+import org.openbravo.test.base.OBBaseTest;
+
+/**
+ * Test the ErrorTextParser class logic by reproducing some scenarios that lead to an error that
+ * should be properly translated by the parser.
+ * 
+ * @author huehner
+ */
+
+public class ErrorTextParserIntegrationTest extends OBBaseTest {
+
+  @Test
+  public void testDuplicatePrimaryKey() throws Exception {
+    doErrorTextParserTest(1);
+  }
+
+  @Test
+  public void testNotNull() throws Exception {
+    // test disabled on pgsql, as its error message text in not-null case cannot be parsed so far
+    if (getConnectionProvider().getRDBMS().equals("ORACLE")) {
+      doErrorTextParserTest(2);
+    }
+  }
+
+  @Test
+  public void testBoolean() throws Exception {
+    doErrorTextParserTest(3);
+  }
+
+  @Test
+  public void testUniqueSingleField() throws Exception {
+    doErrorTextParserTest(4);
+  }
+
+  @Test
+  public void testUniqueMultipleFields() throws Exception {
+    doErrorTextParserTest(5);
+  }
+
+  @Test
+  public void testFKInsert() throws Exception {
+    doErrorTextParserTest(6);
+  }
+
+  @Test
+  public void testFKDelete() throws Exception {
+    doErrorTextParserTest(7);
+  }
+
+  @Test
+  public void testNonBooleanCheck() throws Exception {
+    doErrorTextParserTest(8);
+  }
+
+  @Test
+  public void testTriggerError() throws Exception {
+    doErrorTextParserTest(9);
+  }
+
+  @Test
+  public void whenStatementFailsNoStackTraceIsLoggedByDefault() throws Exception {
+    setTestLogAppenderLevel(Level.INFO);
+    setLogStackTraces(true);
+
+    doErrorTextParserTest(1);
+
+    assertThat(
+        "Stack trace shouldn't be included in log",
+        getTestLogAppender().getMessages(Level.ERROR),
+        not(hasItem(containsString("at org.openbravo.test.system.ErrorTextParserTestData.insertUserPK"))));
+  }
+
+  @Test
+  public void whenStatementFailsStackTraceIsLoggedHavingDebugLogLevel() throws Exception {
+    Logger sqlcLogger = Logger.getLogger(ErrorTextParserTestData.class);
+    Level originalLogLevel = sqlcLogger.getLevel();
+
+    try {
+      setTestLogAppenderLevel(Level.DEBUG);
+      sqlcLogger.setLevel(Level.DEBUG);
+      setLogStackTraces(true);
+
+      doErrorTextParserTest(1);
+
+      assertThat(
+          "Stack trace should be included in log",
+          getTestLogAppender().getMessages(Level.ERROR),
+          hasItem(containsString("at org.openbravo.test.system.ErrorTextParserTestData.insertUserPK")));
+    } finally {
+      sqlcLogger.setLevel(originalLogLevel);
+    }
+  }
+
+  private void doErrorTextParserTest(int testCase) throws Exception {
+    ConnectionProvider conn = getConnectionProvider();
+    VariablesSecureApp vars = new VariablesSecureApp("", "", "");
+    Connection con = conn.getTransactionConnection();
+
+    if (testCase != 9) {
+      // set core to development to avoid the _mod_ trigger restrictions
+      ErrorTextParserTestData.setCoreInDevelopment(con, conn);
+    } else {
+      // ensure that the are not any modules in development
+      ErrorTextParserTestData.setNotInDevelopment(con, conn);
+    }
+
+    String errorMessage = "";
+    String expectedErrorMessage = "";
+    try {
+      switch (testCase) {
+      case 1:
+        expectedErrorMessage = "Internal Error: Duplicate primary key/uuid. Your record has not been saved into the table User/Contact";
+        ErrorTextParserTestData.insertUserPK(con, conn, "0", "N", "name");
+        break;
+      case 2:
+        expectedErrorMessage = "The column Active is mandatory and cannot be left empty.";
+        ErrorTextParserTestData.insertUser(con, conn, null, "name");
+        break;
+      case 3:
+        expectedErrorMessage = "Only values 'Y'or 'N' may be entered into the field Active.";
+        ErrorTextParserTestData.insertUser(con, conn, "B", "name");
+        break;
+      case 4:
+        expectedErrorMessage = "There is already a Client with the same Name. Name must be unique. You must change the values entered.";
+        ErrorTextParserTestData.insertClientWithName(con, conn, "System", "System");
+        break;
+      case 5:
+        expectedErrorMessage = "There is already a Month Translation with the same (Language, Month). (Language, Month) must be unique. You must change the values entered.";
+        ErrorTextParserTestData.insertMonthTrl(con, conn);
+        break;
+      case 6:
+        expectedErrorMessage = "This record cannot be deleted because it is associated with other existing elements. Please see Linked Items";
+        ErrorTextParserTestData.insertUserWithClient(con, conn, "42", "Y", "Openbravo");
+        break;
+      case 7:
+        expectedErrorMessage = "This record cannot be deleted because it is associated with other existing elements. Please see Linked Items";
+        ErrorTextParserTestData.deleteClient(con, conn, "0");
+        break;
+      case 8:
+        expectedErrorMessage = "There is a constraint defined that was not satisfied. Please check the data entered";
+        ErrorTextParserTestData.insertProcess(con, conn, "value", "name", "test");
+        break;
+      case 9:
+        expectedErrorMessage = "Cannot update an object in a module not in development and without an active template";
+        ErrorTextParserTestData.updateTableDescription(con, conn, "description", "146");
+        break;
+      }
+
+    } catch (ServletException se) {
+      errorMessage = se.getMessage();
+    } finally {
+      conn.releaseRollbackConnection(con);
+    }
+    // Ignore the testCase 5 until another two-part unique constraint is found
+    if (testCase != 5) {
+      OBError trlError = Utility.translateError(conn, vars, "en_US", errorMessage);
+
+      assertEquals(expectedErrorMessage, trlError.getMessage());
+    }
+  }
+}
\ No newline at end of file
--- a/src-test/src/org/openbravo/test/system/ErrorTextParserTest.java	Fri Aug 03 16:29:18 2018 +0200
+++ b/src-test/src/org/openbravo/test/system/ErrorTextParserTest.java	Mon Aug 06 08:59:19 2018 +0200
@@ -19,18 +19,11 @@
 
 package org.openbravo.test.system;
 
-import static org.hamcrest.CoreMatchers.containsString;
-import static org.hamcrest.CoreMatchers.not;
-import static org.hamcrest.Matchers.hasItem;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.Matchers.equalTo;
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertThat;
+import static org.junit.Assume.assumeThat;
 
-import java.sql.Connection;
-
-import javax.servlet.ServletException;
-
-import org.apache.log4j.Level;
-import org.apache.log4j.Logger;
 import org.junit.Test;
 import org.openbravo.base.secureApp.VariablesSecureApp;
 import org.openbravo.database.ConnectionProvider;
@@ -47,179 +40,35 @@
 public class ErrorTextParserTest extends OBBaseTest {
 
   @Test
-  public void testDuplicatePrimaryKey() throws Exception {
-    doErrorTextParserTest(1);
+  public void testPGSpanish() throws Exception {
+    // only test on pgsql, as specifically testing against es_ES/pgsql error messsage
+    assumeThat("Executing only in PostgreSQL", getConnectionProvider().getRDBMS(),
+        is(equalTo("POSTGRE")));
+    String expectedMessage = "This record cannot be deleted because it is associated with other existing elements. Please see Linked Items";
+    String errorMessage = "inserción o actualización en la tabla «c_bpartner» viola la llave foránea «c_bpartner_c_bp_group»";
+    doErrorTextParserTestWithoutDB(errorMessage, expectedMessage);
   }
 
   @Test
-  public void testNotNull() throws Exception {
-    // test disabled on pgsql, as its error message text in not-null case cannot be parsed so far
-    if (getConnectionProvider().getRDBMS().equals("ORACLE")) {
-      doErrorTextParserTest(2);
+  public void testMultipleMessages() throws Exception {
+    String messagePrefix;
+    if ("POSTGRE".equals(getConnectionProvider().getRDBMS())) {
+      messagePrefix = "ERROR: ";
+    } else {
+      messagePrefix = "ORA-20000: ";
     }
+    String expectedMessage = "There is no conversion rate defined from (USD-$) to (AED-د.إ) for date '09-02-2015', Client 'F&B International Group' and Organization 'F&B US East Coast'.";
+    String errorMessage = messagePrefix
+        + "@NoConversionRate@ (USD-$) @to@ (AED-د.إ) @ForDate@ '09-02-2015', @Client@ 'F&B International Group' @And@ @ACCS_AD_ORG_ID_D@ 'F&B US East Coast'.";
+    doErrorTextParserTestWithoutDB(errorMessage, expectedMessage);
   }
 
-  @Test
-  public void testBoolean() throws Exception {
-    doErrorTextParserTest(3);
-  }
-
-  @Test
-  public void testUniqueSingleField() throws Exception {
-    doErrorTextParserTest(4);
-  }
-
-  @Test
-  public void testUniqueMultipleFields() throws Exception {
-    doErrorTextParserTest(5);
-  }
-
-  @Test
-  public void testFKInsert() throws Exception {
-    doErrorTextParserTest(6);
-  }
-
-  @Test
-  public void testFKDelete() throws Exception {
-    doErrorTextParserTest(7);
-  }
-
-  @Test
-  public void testNonBooleanCheck() throws Exception {
-    doErrorTextParserTest(8);
-  }
-
-  @Test
-  public void testTriggerError() throws Exception {
-    doErrorTextParserTest(9);
-  }
-
-  @Test
-  public void testPGSpanish() throws Exception {
-    // only test on pgsql, as specifically testing against es_ES/pgsql error messsage
-    if (getConnectionProvider().getRDBMS().equals("POSTGRE")) {
-      doErrorTextParserTestWithoutDB(1);
-    }
-  }
-
-  @Test
-  public void whenStatementFailsNoStackTraceIsLoggedByDefault() throws Exception {
-    setTestLogAppenderLevel(Level.INFO);
-    setLogStackTraces(true);
-
-    doErrorTextParserTest(1);
-
-    assertThat(
-        "Stack trace shouldn't be included in log",
-        getTestLogAppender().getMessages(Level.ERROR),
-        not(hasItem(containsString("at org.openbravo.test.system.ErrorTextParserTestData.insertUserPK"))));
-  }
-
-  @Test
-  public void whenStatementFailsStackTraceIsLoggedHavingDebugLogLevel() throws Exception {
-    Logger sqlcLogger = Logger.getLogger(ErrorTextParserTestData.class);
-    Level originalLogLevel = sqlcLogger.getLevel();
-
-    try {
-      setTestLogAppenderLevel(Level.DEBUG);
-      sqlcLogger.setLevel(Level.DEBUG);
-      setLogStackTraces(true);
-
-      doErrorTextParserTest(1);
-
-      assertThat(
-          "Stack trace should be included in log",
-          getTestLogAppender().getMessages(Level.ERROR),
-          hasItem(containsString("at org.openbravo.test.system.ErrorTextParserTestData.insertUserPK")));
-    } finally {
-      sqlcLogger.setLevel(originalLogLevel);
-    }
-  }
-
-  private void doErrorTextParserTest(int testCase) throws Exception {
+  private void doErrorTextParserTestWithoutDB(String errorMessage, String expectedMessage)
+      throws Exception {
     ConnectionProvider conn = getConnectionProvider();
     VariablesSecureApp vars = new VariablesSecureApp("", "", "");
-    Connection con = conn.getTransactionConnection();
-
-    if (testCase != 9) {
-      // set core to development to avoid the _mod_ trigger restrictions
-      ErrorTextParserTestData.setCoreInDevelopment(con, conn);
-    } else {
-      // ensure that the are not any modules in development
-      ErrorTextParserTestData.setNotInDevelopment(con, conn);
-    }
-
-    String errorMessage = "";
-    String expectedErrorMessage = "";
-    try {
-      switch (testCase) {
-      case 1:
-        expectedErrorMessage = "Internal Error: Duplicate primary key/uuid. Your record has not been saved into the table User/Contact";
-        ErrorTextParserTestData.insertUserPK(con, conn, "0", "N", "name");
-        break;
-      case 2:
-        expectedErrorMessage = "The column Active is mandatory and cannot be left empty.";
-        ErrorTextParserTestData.insertUser(con, conn, null, "name");
-        break;
-      case 3:
-        expectedErrorMessage = "Only values 'Y'or 'N' may be entered into the field Active.";
-        ErrorTextParserTestData.insertUser(con, conn, "B", "name");
-        break;
-      case 4:
-        expectedErrorMessage = "There is already a Client with the same Name. Name must be unique. You must change the values entered.";
-        ErrorTextParserTestData.insertClientWithName(con, conn, "System", "System");
-        break;
-      case 5:
-        expectedErrorMessage = "There is already a Month Translation with the same (Language, Month). (Language, Month) must be unique. You must change the values entered.";
-        ErrorTextParserTestData.insertMonthTrl(con, conn);
-        break;
-      case 6:
-        expectedErrorMessage = "This record cannot be deleted because it is associated with other existing elements. Please see Linked Items";
-        ErrorTextParserTestData.insertUserWithClient(con, conn, "42", "Y", "Openbravo");
-        break;
-      case 7:
-        expectedErrorMessage = "This record cannot be deleted because it is associated with other existing elements. Please see Linked Items";
-        ErrorTextParserTestData.deleteClient(con, conn, "0");
-        break;
-      case 8:
-        expectedErrorMessage = "There is a constraint defined that was not satisfied. Please check the data entered";
-        ErrorTextParserTestData.insertProcess(con, conn, "value", "name", "test");
-        break;
-      case 9:
-        expectedErrorMessage = "Cannot update an object in a module not in development and without an active template";
-        ErrorTextParserTestData.updateTableDescription(con, conn, "description", "146");
-        break;
-      }
-
-    } catch (ServletException se) {
-      errorMessage = se.getMessage();
-    } finally {
-      conn.releaseRollbackConnection(con);
-    }
-    // Ignore the testCase 5 until another two-part unique constraint is found
-    if (testCase != 5) {
-      OBError trlError = Utility.translateError(conn, vars, "en_US", errorMessage);
-
-      assertEquals(expectedErrorMessage, trlError.getMessage());
-    }
-  }
-
-  private void doErrorTextParserTestWithoutDB(int testCase) throws Exception {
-    String errorMessage = "";
-    String expectedMessage = "";
-    ConnectionProvider conn = getConnectionProvider();
-    VariablesSecureApp vars = new VariablesSecureApp("", "", "");
-
-    switch (testCase) {
-    case 1:
-      expectedMessage = "This record cannot be deleted because it is associated with other existing elements. Please see Linked Items";
-      errorMessage = "inserción o actualización en la tabla «c_bpartner» viola la llave foránea «c_bpartner_c_bp_group»";
-      break;
-    }
-
     OBError trlError = Utility.translateError(conn, vars, "en_US", errorMessage);
     assertEquals(expectedMessage, trlError.getMessage());
-
   }
 
 }
\ No newline at end of file
--- a/src/org/openbravo/costing/AverageCostAdjustment.java	Fri Aug 03 16:29:18 2018 +0200
+++ b/src/org/openbravo/costing/AverageCostAdjustment.java	Mon Aug 06 08:59:19 2018 +0200
@@ -178,7 +178,7 @@
             cost.toPlainString());
       }
       if (basetrx.getMaterialMgmtCostingList().isEmpty()) {
-        Date newDate = new Date();
+        Date newDate = basetrx.getTransactionProcessDate();
         Date dateTo = costing.getEndingDate();
         costing.setEndingDate(newDate);
         Costing newCosting = OBProvider.getInstance().get(Costing.class);
--- a/src/org/openbravo/erpCommon/utility/ErrorTextParserPOSTGRE.java	Fri Aug 03 16:29:18 2018 +0200
+++ b/src/org/openbravo/erpCommon/utility/ErrorTextParserPOSTGRE.java	Mon Aug 06 08:59:19 2018 +0200
@@ -11,7 +11,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-2018 Openbravo SLU 
+ * All portions are Copyright (C) 2001-2017 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -146,10 +146,9 @@
      */
     // The regular expression . matches any character except a line terminator unless the DOTALL
     // flag is specified.
-    Pattern pattern = Pattern.compile("(.*)(@.+@)(.*)", Pattern.DOTALL);
-    Matcher matcher = pattern.matcher(myMessage);
-    if (matcher.matches()) {
-      myMessage = matcher.group(2);
+    Pattern pattern = Pattern.compile(".*@.+@.*", Pattern.DOTALL);
+    if (pattern.matcher(myMessage).matches()) {
+      myMessage = stripExtraInformation(myMessage);
       String translatedMsg = Utility.parseTranslation(getConnection(), getVars(), getLanguage(),
           myMessage);
       log4j.debug("translated message: {}", translatedMsg);
@@ -198,4 +197,21 @@
     originalError.setMessage(getMessage());
     return originalError;
   }
+
+  private String stripExtraInformation(String message) {
+    String cleanedMessage;
+    // if the message is a directly from postgres generated one, it has an 'ERROR :' prefix
+    // if it is passed via an AD_PINSTACE result, then the 'ERROR: ' has already been stripped
+    if ((message.length() > 7) && (message.startsWith("ERROR: "))) {
+      cleanedMessage = message.substring(7);
+    } else {
+      cleanedMessage = message;
+    }
+    // remove technical information added by the PostgreSQL JDBC driver
+    int pos = cleanedMessage.indexOf("\n  Where: ");
+    if (pos != -1) {
+      cleanedMessage = cleanedMessage.substring(0, pos);
+    }
+    return cleanedMessage;
+  }
 }
--- a/src/org/openbravo/materialmgmt/ManageVariantsDS.java	Fri Aug 03 16:29:18 2018 +0200
+++ b/src/org/openbravo/materialmgmt/ManageVariantsDS.java	Mon Aug 06 08:59:19 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;
--- a/src/org/openbravo/service/db/DbUtility.java	Fri Aug 03 16:29:18 2018 +0200
+++ b/src/org/openbravo/service/db/DbUtility.java	Mon Aug 06 08:59:19 2018 +0200
@@ -11,7 +11,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) 2008-2010 Openbravo SLU 
+ * All portions are Copyright (C) 2008-2018 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -72,6 +72,11 @@
           .getCause();
       return cve.getSQLException().getNextException();
     }
+
+    if (throwable.getCause() instanceof SQLException) {
+      return throwable.getCause();
+    }
+
     return throwable;
   }
 
--- a/web/js/productCharacteristicsProcess.js	Fri Aug 03 16:29:18 2018 +0200
+++ b/web/js/productCharacteristicsProcess.js	Mon Aug 06 08:59:19 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'));
     }
   },
 };