# HG changeset patch
# User Carlos Aristu <carlos.aristu@openbravo.com>
# Date 1506584845 -7200
#      Thu Sep 28 09:47:25 2017 +0200
# Node ID 383b62bdfdd02ffe1f50a86d66f3d2ef20b754c4
# Parent  41d803d057a2a92b2f80f4a3ff82108c69cdb54b
fixes bug 35136: Line seems to be saved with error after saving the header

  When saving a record, the content of its child tabs is automatically refreshed. In case we leave a child record in error status and then we edit and save its parent record, the content of the child record is automatically refreshed with the server data and the error state in the UI disappears, nevertheless, the problem was that the edits was not being discarded properly causing the record to show outdated information.

  Now when the tab is refreshed if it contains records with errors, then the edits are discarded allowing to show the real contents of the records.

diff --git a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/main/ob-standard-view.js b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/main/ob-standard-view.js
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/main/ob-standard-view.js
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/main/ob-standard-view.js
@@ -1249,6 +1249,12 @@
     if (keepSelection) {
       callback = function () {
         var length, i, recordIndex;
+
+        if (me.viewGrid.gridHasValidationErrors()) {
+          // there are unsaved records with errors: discard the changes in order to show the refreshed data
+          me.viewGrid.discardAllEdits();
+        }
+
         length = me.viewGrid.recordsSelectedBeforeRefresh.length;
         for (i = 0; i < length; i++) {
           recordIndex = me.viewGrid.getRecordIndex(me.viewGrid.recordsSelectedBeforeRefresh[i]);
