Fixes bug 24402, fixes bug 24403: Grid Datasource load minimum property set
authorAugusto Mauch <augusto.mauch@openbravo.com>
Mon, 07 Oct 2013 17:17:08 +0200
changeset 21243 94d0fb151919
parent 21242 43459dd69e37
child 21244 9c0d7420d284
Fixes bug 24402, fixes bug 24403: Grid Datasource load minimum property set

Changes with respect to changeset 20851:
- In the FIC, do not try to set in the session the values of properties that are empty in the request due to being shown only in grid view. In this case the value that will prevail will be the one present in the database.
- New mandatory property fields:
* Client and organization
* Button fields with label values
* Link to parent properties
- In the grid, do not detect as a change if a value change from undefined to not undefined. Otherwise, when the user opens a record in form view the record would appear as changed. This happens because the properties that are present in the form but not in the grid change from undefined to not undefined.
- The fieldStateChanged function has been deleted. This function handled the case when the user added a new column to the grid while it was being edited. This action is no longer allowed, so the function serves no purpose.
- The FIC call in the setContextInfo has been changed from SETSESSION to EDIT, because now in the response we need the values of all the view fields, not only the shown in the grid. A callback has been defined to apply this new values to the grid.
modules/org.openbravo.client.application/src-db/database/sourcedata/AD_MESSAGE.xml
modules/org.openbravo.client.application/src/org/openbravo/client/application/templates/ob-view-grid.js.ftl
modules/org.openbravo.client.application/src/org/openbravo/client/application/window/FormInitializationComponent.java
modules/org.openbravo.client.application/src/org/openbravo/client/application/window/OBViewFieldHandler.java
modules/org.openbravo.client.application/src/org/openbravo/client/application/window/OBViewGridComponent.java
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/ob-view-form.js
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/grid/ob-grid.js
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/grid/ob-view-grid.js
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/main/ob-standard-view-datasource.js
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/main/ob-standard-view.js
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/toolbar/ob-toolbar.js
--- a/modules/org.openbravo.client.application/src-db/database/sourcedata/AD_MESSAGE.xml	Mon Oct 07 15:22:32 2013 +0200
+++ b/modules/org.openbravo.client.application/src-db/database/sourcedata/AD_MESSAGE.xml	Mon Oct 07 17:17:08 2013 +0200
@@ -1266,6 +1266,18 @@
 <!--B8C1706AB7C34C0EA750048CD68E314A-->  <ISINCLUDEINI18N><![CDATA[N]]></ISINCLUDEINI18N>
 <!--B8C1706AB7C34C0EA750048CD68E314A--></AD_MESSAGE>
 
+<!--BCA6318A99B54DB5A27D319C6569316B--><AD_MESSAGE>
+<!--BCA6318A99B54DB5A27D319C6569316B-->  <AD_MESSAGE_ID><![CDATA[BCA6318A99B54DB5A27D319C6569316B]]></AD_MESSAGE_ID>
+<!--BCA6318A99B54DB5A27D319C6569316B-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--BCA6318A99B54DB5A27D319C6569316B-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--BCA6318A99B54DB5A27D319C6569316B-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--BCA6318A99B54DB5A27D319C6569316B-->  <VALUE><![CDATA[OBUIAPP_NotAddingFieldsWhileGridEditing]]></VALUE>
+<!--BCA6318A99B54DB5A27D319C6569316B-->  <MSGTEXT><![CDATA[New fields cannot be added to the grid while it is being edited.]]></MSGTEXT>
+<!--BCA6318A99B54DB5A27D319C6569316B-->  <MSGTYPE><![CDATA[E]]></MSGTYPE>
+<!--BCA6318A99B54DB5A27D319C6569316B-->  <AD_MODULE_ID><![CDATA[9BA0836A3CD74EE4AB48753A47211BCC]]></AD_MODULE_ID>
+<!--BCA6318A99B54DB5A27D319C6569316B-->  <ISINCLUDEINI18N><![CDATA[N]]></ISINCLUDEINI18N>
+<!--BCA6318A99B54DB5A27D319C6569316B--></AD_MESSAGE>
+
 <!--C415C626CAE14E35A7F05C42F11DA114--><AD_MESSAGE>
 <!--C415C626CAE14E35A7F05C42F11DA114-->  <AD_MESSAGE_ID><![CDATA[C415C626CAE14E35A7F05C42F11DA114]]></AD_MESSAGE_ID>
 <!--C415C626CAE14E35A7F05C42F11DA114-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
--- a/modules/org.openbravo.client.application/src/org/openbravo/client/application/templates/ob-view-grid.js.ftl	Mon Oct 07 15:22:32 2013 +0200
+++ b/modules/org.openbravo.client.application/src/org/openbravo/client/application/templates/ob-view-grid.js.ftl	Mon Oct 07 17:17:08 2013 +0200
@@ -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) 2010-2011 Openbravo SLU
+ * All portions are Copyright (C) 2010-2013 Openbravo SLU
  * All Rights Reserved.
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -38,7 +38,11 @@
     <#if data.filterName != "">
         filterName: '${data.filterName?js_string}',
     </#if>
-    
+    //List of properties  that must be always included in this grid
+    requiredGridProperties: [
+    <#list data.requiredGridProperties as property>
+        '${property?js_string}'<#if property_has_next>,</#if>
+    </#list>],
     // the this is the view instance
     fields: this.gridFields
 })
--- a/modules/org.openbravo.client.application/src/org/openbravo/client/application/window/FormInitializationComponent.java	Mon Oct 07 15:22:32 2013 +0200
+++ b/modules/org.openbravo.client.application/src/org/openbravo/client/application/window/FormInitializationComponent.java	Mon Oct 07 17:17:08 2013 +0200
@@ -169,6 +169,10 @@
       if (jsContent.has("_visibleProperties")) {
         visibleProperties = convertJSONArray(jsContent.getJSONArray("_visibleProperties"));
       }
+      List<String> gridVisibleProperties = new ArrayList<String>();
+      if (jsContent.has("_gridVisibleProperties")) {
+        gridVisibleProperties = convertJSONArray(jsContent.getJSONArray("_gridVisibleProperties"));
+      }
 
       // If the table is based in a datasource, don't try to create a BaseOBObject
       if (!dataSourceBasedTable) {
@@ -242,7 +246,7 @@
       long t5 = System.currentTimeMillis();
       computeColumnValues(mode, tab, allColumns, columnValues, parentRecord, parentId,
           changedColumn, jsContent, changeEventCols, calloutsToCall, lastfieldChanged,
-          visibleProperties);
+          visibleProperties, gridVisibleProperties);
 
       if (mode.equals("NEW")) {
         // In the case of NEW mode, we compute auxiliary inputs again to take into account that
@@ -537,7 +541,8 @@
   private void computeColumnValues(String mode, Tab tab, List<String> allColumns,
       Map<String, JSONObject> columnValues, BaseOBObject parentRecord, String parentId,
       String changedColumn, JSONObject jsContent, List<String> changeEventCols,
-      List<String> calloutsToCall, List<String> lastfieldChanged, List<String> visibleProperties) {
+      List<String> calloutsToCall, List<String> lastfieldChanged, List<String> visibleProperties,
+      List<String> gridVisibleProperties) {
     boolean forceComboReload = (mode.equals("CHANGE") && changedColumn == null);
     if (mode.equals("CHANGE") && changedColumn != null) {
       RequestContext.get().setRequestParameter("donotaddcurrentelement", "true");
@@ -654,12 +659,23 @@
               changedCols.add(field.getColumn().getDBColumnName());
             }
           }
+
           columnValues
               .put("inp" + Sqlc.TransformaNombreColumna(field.getColumn().getDBColumnName()),
                   jsonobject);
           setRequestContextParameter(field, jsonobject);
+
+          String fullPropertyName = null;
+          if (field.getProperty() != null) {
+            fullPropertyName = field.getProperty().replace('.', '$');
+          } else {
+            fullPropertyName = prop.getName();
+          }
+
           // We also set the session value for the column in Edit or SetSession mode
-          if (mode.equals("NEW") || mode.equals("EDIT") || mode.equals("SETSESSION")) {
+          if (gridVisibleProperties.contains(fullPropertyName)
+              && (mode.equals("NEW") || mode.equals("EDIT") || mode.equals("SETSESSION"))) {
+
             if (field.getColumn().isStoredInSession() || field.getColumn().isKeyColumn()) {
               setSessionValue(tab.getWindow().getId() + "|"
                   + field.getColumn().getDBColumnName().toUpperCase(),
@@ -821,13 +837,22 @@
     // database
     if (mode.equals("EDIT") && !dataSourceBasedTable) {
       // In EDIT mode we initialize them from the database
-      for (Field field : fields) {
-        if (field.getColumn() == null) {
-          continue;
-        }
-        setValueOfColumnInRequest(row, field, field.getColumn().getDBColumnName());
+      List<Column> columns = getADColumnList(tab.getTable().getId());
+
+      for (Column column : columns) {
+        setValueOfColumnInRequest(row, null, column.getDBColumnName());
       }
     }
+
+    List<String> gridVisibleProperties = new ArrayList<String>();
+    if (jsContent.has("_gridVisibleProperties")) {
+      try {
+        gridVisibleProperties = convertJSONArray(jsContent.getJSONArray("_gridVisibleProperties"));
+      } catch (JSONException e) {
+        log.error("Error while retrieving _gridVisibleProperties from jsContent" + jsContent, e);
+      }
+    }
+
     // and then overwrite with what gets passed in
     if (mode.equals("EDIT") || mode.equals("CHANGE") || mode.equals("SETSESSION")) {
       // In CHANGE and SETSESSION we get them from the request
@@ -835,7 +860,20 @@
         if (field.getColumn() == null) {
           continue;
         }
+        // Do not overwrite the value of fields that are not visible in the grid, because they are
+        // empty in the request
+
         final Property prop = KernelUtils.getInstance().getPropertyFromColumn(field.getColumn());
+        String fullPropertyName = null;
+        if (field.getProperty() != null) {
+          fullPropertyName = field.getProperty().replace('.', '$');
+        } else {
+          fullPropertyName = prop.getName();
+        }
+        if ((mode.equals("EDIT") || mode.equals("SETSESSION"))
+            && !gridVisibleProperties.contains(fullPropertyName)) {
+          continue;
+        }
         String inpColName = "inp"
             + Sqlc.TransformaNombreColumna(field.getColumn().getDBColumnName());
         try {
--- a/modules/org.openbravo.client.application/src/org/openbravo/client/application/window/OBViewFieldHandler.java	Mon Oct 07 15:22:32 2013 +0200
+++ b/modules/org.openbravo.client.application/src/org/openbravo/client/application/window/OBViewFieldHandler.java	Mon Oct 07 17:17:08 2013 +0200
@@ -73,6 +73,7 @@
 
   private List<String> windowEntities = null;
   private List<OBViewFieldDefinition> fields;
+  private List<String> propertiesInButtonFieldDisplayLogic = new ArrayList<String>();
 
   private List<Field> ignoredFields = new ArrayList<Field>();
 
@@ -94,7 +95,8 @@
   }
 
   public List<OBViewFieldDefinition> getFields() {
-
+    final Entity entity = ModelProvider.getInstance().getEntityByTableId(
+        getTab().getTable().getId());
     if (fields != null) {
       return fields;
     }
@@ -129,6 +131,15 @@
         if (!fieldsInDynamicExpression.contains(fieldExpression)) {
           fieldsInDynamicExpression.add(fieldExpression);
         }
+        // All the properties that are used in the display logic of the buttons must be included in
+        // the list of grid mandatory columns
+        if ("Button".equals(f.getColumn().getReference().getName())) {
+          Property property = entity.getPropertyByColumnName(fieldExpression.getColumn()
+              .getDBColumnName());
+          if (!propertiesInButtonFieldDisplayLogic.contains(property.getName())) {
+            propertiesInButtonFieldDisplayLogic.add(property.getName());
+          }
+        }
       }
     }
 
@@ -2043,4 +2054,9 @@
     getFields(); // initializes stuff
     return ignoredFields;
   }
+
+  public List<String> getPropertiesInButtonFieldDisplayLogic() {
+    return propertiesInButtonFieldDisplayLogic;
+  }
+
 }
--- a/modules/org.openbravo.client.application/src/org/openbravo/client/application/window/OBViewGridComponent.java	Mon Oct 07 15:22:32 2013 +0200
+++ b/modules/org.openbravo.client.application/src/org/openbravo/client/application/window/OBViewGridComponent.java	Mon Oct 07 17:17:08 2013 +0200
@@ -18,14 +18,19 @@
  */
 package org.openbravo.client.application.window;
 
+import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 import org.openbravo.base.model.Entity;
 import org.openbravo.base.model.ModelProvider;
+import org.openbravo.base.model.Property;
 import org.openbravo.client.application.window.OBViewFieldHandler.OBViewField;
 import org.openbravo.client.application.window.OBViewFieldHandler.OBViewFieldDefinition;
+import org.openbravo.client.application.window.OBViewTab.ButtonField;
 import org.openbravo.client.kernel.BaseTemplateComponent;
+import org.openbravo.client.kernel.KernelUtils;
 import org.openbravo.client.kernel.RequestContext;
 import org.openbravo.client.kernel.Template;
 import org.openbravo.dal.core.DalUtil;
@@ -231,4 +236,65 @@
     this.viewTab = viewTab;
   }
 
+  /**
+   * Returns the string representation of an array that contains all the properties that must always
+   * be returned from the datasource when the grid asks for data: 
+   * - id 
+   * - client and organization
+   * - all the properties that compose the identifier of the entity 
+   * - all button fields with label values
+   * - the link to parent properties
+   * - all the properties that are part of the display logic of the tab buttons
+   */
+  public List<String> getRequiredGridProperties() {
+    List<String> requiredGridProperties = new ArrayList<String>();
+    requiredGridProperties.add("id");
+    requiredGridProperties.add("client");
+    requiredGridProperties.add("organization");
+
+    for (Property identifierProperty : this.entity.getIdentifierProperties()) {
+      requiredGridProperties.add(identifierProperty.getName());
+    }
+
+    List<ButtonField> buttonFields = getViewTab().getButtonFields();
+    for (ButtonField buttonField : buttonFields) {
+      if (!buttonField.getLabelValues().isEmpty()) {
+        requiredGridProperties.add(buttonField.getPropertyName());
+      }
+    }
+
+    List<String> propertiesInButtonFieldDisplayLogic = getViewTab().getFieldHandler()
+        .getPropertiesInButtonFieldDisplayLogic();
+
+    for (String propertyName : propertiesInButtonFieldDisplayLogic) {
+      requiredGridProperties.add(propertyName);
+    }
+
+    String linkToParentPropertyName = this.getLinkToParentPropertyName();
+    if (linkToParentPropertyName != null && !linkToParentPropertyName.isEmpty()) {
+      requiredGridProperties.add(linkToParentPropertyName);
+    }
+
+    return requiredGridProperties;
+  }
+
+  private String getLinkToParentPropertyName() {
+    Tab parentTab = KernelUtils.getInstance().getParentTab(tab);
+    if (parentTab == null) {
+      return null;
+    }
+    List<Property> linkToparentPropertyList = entity.getParentProperties();
+    if (linkToparentPropertyList.isEmpty()) {
+      return null;
+    }
+    String parentTableId = parentTab.getTable().getId();
+    for (Property linkToParentProperty : linkToparentPropertyList) {
+      Property referencedProperty = linkToParentProperty.getReferencedProperty();
+      String referencedTableId = referencedProperty.getEntity().getTableId();
+      if (parentTableId.equals(referencedTableId)) {
+        return linkToParentProperty.getName();
+      }
+    }
+    return null;
+  }
 }
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/ob-view-form.js	Mon Oct 07 15:22:32 2013 +0200
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/ob-view-form.js	Mon Oct 07 17:17:08 2013 +0200
@@ -543,6 +543,22 @@
     return this.fieldsByColumnName[columnName.toLowerCase()];
   },
 
+  getFieldFromFieldName: function (fieldName) {
+    var i, length, localResult, fields;
+    if (!this.fieldsByFieldName) {
+      localResult = [];
+      fields = this.getFields();
+      length = fields.length;
+      for (i = 0; i < fields.length; i++) {
+        if (fields[i].name) {
+          localResult[fields[i].name] = fields[i];
+        }
+      }
+      this.fieldsByFieldName = localResult;
+    }
+    return this.fieldsByFieldName[fieldName];
+  },
+
   setFields: function () {
     var i, item, length;
 
@@ -567,7 +583,9 @@
     var parentId = this.view.getParentId(),
         i, fldNames = [],
         requestParams, allProperties, parentColumn, me = this,
-        mode, length = this.getFields().length;
+        mode, length = this.getFields().length,
+        gridVisibleProperties = [],
+        len;
 
     this.setParentDisplayInfo();
 
@@ -593,6 +611,18 @@
       requestParams[parentColumn] = parentId;
     }
 
+    if (this.view && this.view.viewGrid && this.view.viewGrid.fields) {
+      gridVisibleProperties.push('id');
+      len = this.view.viewGrid.fields.length;
+      for (i = 0; i < len; i++) {
+        if (this.view.viewGrid.fields[i].name[0] !== '_') {
+          gridVisibleProperties.push(this.view.viewGrid.fields[i].name);
+        }
+      }
+      allProperties._gridVisibleProperties = gridVisibleProperties;
+    }
+
+
     allProperties._entityName = this.view.entity;
 
     // only put the visible field names in the call
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/grid/ob-grid.js	Mon Oct 07 15:22:32 2013 +0200
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/grid/ob-grid.js	Mon Oct 07 17:17:08 2013 +0200
@@ -718,7 +718,8 @@
         dsURL = this.dataSource.dataURL;
     var sortCriteria;
     var lcriteria = this.getCriteria();
-    var gdata = this.getData();
+    var gdata = this.getData(),
+        isExporting = true;
     if (gdata && gdata.dataSource) {
       lcriteria = gdata.dataSource.convertRelativeDates(lcriteria);
     }
@@ -735,7 +736,7 @@
       exportToFile: true,
       _textMatchStyle: 'substring',
       _UTCOffsetMiliseconds: OB.Utilities.Date.getUTCOffsetInMiliseconds()
-    }, lcriteria, this.getFetchRequestParams());
+    }, lcriteria, this.getFetchRequestParams(null, isExporting));
     if (this.getSortField()) {
       sortCriteria = this.getSort();
       if (sortCriteria && sortCriteria.length > 0) {
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/grid/ob-view-grid.js	Mon Oct 07 15:22:32 2013 +0200
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/grid/ob-view-grid.js	Mon Oct 07 17:17:08 2013 +0200
@@ -974,12 +974,19 @@
 
   showField: function (field, suppressRelayout) {
     var res;
+    // Do not allow to add a new field while the grid is being edited. Adding a new field implies a grid refresh, 
+    // and the refresh toolbar button is disabled while the grid/form is being edited
+    if (this.view.isEditingGrid) {
+      this.view.messageBar.setMessage(isc.OBMessageBar.TYPE_ERROR, OB.I18N.getLabel('OBUIAPP_Error'), OB.I18N.getLabel('OBUIAPP_NotAddingFieldsWhileGridEditing'));
+      return;
+    }
     this._showingField = true;
     this._savedEditValues = this.getEditValues(this.getEditRow());
     res = this.Super('showField', arguments);
     delete this._savedEditValues;
     delete this._showingField;
     this.view.standardWindow.storeViewState();
+    this.invalidateCache();
     this.refreshContents();
     return res;
   },
@@ -1966,7 +1973,8 @@
     requestProperties.params = this.getFetchRequestParams(requestProperties.params);
   },
 
-  getFetchRequestParams: function (params) {
+  getFetchRequestParams: function (params, isExporting) {
+    var i, len, first, selectedProperties;
     params = params || {};
 
     if (this.targetRecordId) {
@@ -2010,6 +2018,29 @@
     } else {
       params[OB.Constants.WHERE_PARAMETER] = null;
     }
+
+    if (!isExporting) {
+      first = true;
+      selectedProperties = '';
+      len = this.requiredGridProperties.length;
+      for (i = 0; i < len; i++) {
+        if (first) {
+          first = false;
+          selectedProperties = selectedProperties + this.requiredGridProperties[i];
+        } else {
+          selectedProperties = selectedProperties + ',' + this.requiredGridProperties[i];
+        }
+      }
+
+      len = this.fields.length;
+      for (i = 0; i < len; i++) {
+        if (this.fields[i].name[0] !== '_') {
+          selectedProperties = selectedProperties + ',';
+          selectedProperties = selectedProperties + this.fields[i].name;
+        }
+      }
+      params._selectedProperties = selectedProperties;
+    }
     return params;
   },
 
@@ -2694,7 +2725,7 @@
     }
   },
 
-  recordHasChanges: function (rowNum) {
+  recordHasChanges: function (rowNum, colNum, checkEditor) {
     var record = this.getRecord(rowNum);
     // If a record has validation errors but had all the mandatory fields set,
     // smartclient's recordHasChanges will return false, and the record will be cleared (see ListGrid.hideInlineEditor function)
@@ -2702,11 +2733,44 @@
     // See issue https://issues.openbravo.com/view.php?id=22123
     if (record && record._hasValidationErrors) {
       return true;
+    } else if (!this.recordHasActualChanges(rowNum, colNum, checkEditor)) {
+      return false;
     } else {
       return this.Super('recordHasChanges', arguments);
     }
   },
 
+  // Checks if there are changes in the other other than a field changing from undefined to not undefined
+  // Those kind of changes happen when a row is opened in edit mode, they should not be detected as an actual change
+  recordHasActualChanges: function (rowNum, colNum, checkEditor) {
+    var newValues, oldValues, changes = false,
+        fieldName, oldFieldValue, newFieldValue, i, len, isNew;
+    if (!checkEditor) {
+      checkEditor = true;
+    }
+    newValues = (checkEditor ? this.getEditValues(rowNum, colNum) : this.getEditSession(rowNum, colNum));
+    oldValues = this.getCellRecord(rowNum);
+    if (!oldValues) {
+      return true;
+    }
+    isNew = this.getEditForm() ? this.getEditForm().isNew : false;
+    for (fieldName in newValues) {
+      if (newValues.hasOwnProperty(fieldName)) {
+        if (fieldName === this.removeRecordProperty) {
+          continue;
+        }
+        oldFieldValue = oldValues[fieldName];
+        newFieldValue = newValues[fieldName];
+        // Use custom comparator to catch things like Dates where '==' check is not sufficient
+        if ((isNew || oldFieldValue !== undefined) && !this.fieldValuesAreEqual(this.getField(fieldName), oldFieldValue, newFieldValue)) {
+          changes = true;
+          break;
+        }
+      }
+    }
+    return changes;
+  },
+
   editComplete: function (rowNum, colNum, newValues, oldValues, editCompletionEvent, dsResponse) {
 
     var record = this.getRecord(rowNum),
@@ -2840,7 +2904,7 @@
         totalRows, me = this,
         record = this.getRecord(rowNum);
 
-    if (!preventConfirm && (editForm.hasChanged || this.rowHasErrors(rowNum))) {
+    if (!preventConfirm && ((editForm && editForm.hasChanged) || this.rowHasErrors(rowNum))) {
       me.Super('discardEdits', localArguments);
 
       // remove the record if new
@@ -3532,31 +3596,56 @@
     return this.editLinkColNum === colNum;
   },
 
-  // This method forces a FIC call in case the user has changed the visible fields,
-  // if there is a record being edited
-  // This is done to load all the potentially missing combos
-  fieldStateChanged: function () {
-    var undef;
-    if (this.getEditRow() !== undef && this.getEditRow() !== null) {
-      this.getEditForm().doChangeFICCall(null, true);
-    }
-    this.Super('fieldStateChanged', arguments);
-  },
-
   getFieldFromColumnName: function (columnName) {
-    var i, field, length, fields = this.completeFields;
+    var i, field, length, fields = this.view.propertyToColumns;
 
     length = fields.length;
 
     for (i = 0; i < fields.length; i++) {
-      if (fields[i].columnName === columnName) {
+      if (fields[i].dbColumn === columnName) {
         field = fields[i];
         break;
       }
     }
     return field;
+  },
+
+  processColumnValue: function (rowNum, columnName, columnValue) {
+    var field, newValue;
+    if (!columnValue) {
+      return;
+    }
+    field = this.getFieldFromColumnName(columnName);
+    if (!field) {
+      return;
+    }
+    newValue = {};
+    newValue[field.property] = columnValue.value;
+    this.setEditValue(rowNum, field.property, columnValue.value);
+  },
+
+  processFICReturn: function (response, data, request) {
+    var context = response && response.clientContext,
+        rowNum = context && context.rowNum,
+        grid = context && context.grid,
+        columnValues, prop, value, undef, field;
+
+    if (rowNum === undef || !data || !data.columnValues) {
+      return;
+    }
+    columnValues = data.columnValues;
+
+    for (prop in columnValues) {
+      if (columnValues.hasOwnProperty(prop)) {
+        field = this.getFieldFromColumnName(prop);
+        // This call to the FIC was done to retrieve the missing values
+        // Do not try to overwrite the existing values
+        if (!this.getRecord(rowNum)[field.property]) {
+          grid.processColumnValue(rowNum, prop, columnValues[prop]);
+        }
+      }
+    }
   }
-
 });
 
 // = OBGridToolStripIcon =
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/main/ob-standard-view-datasource.js	Mon Oct 07 15:22:32 2013 +0200
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/main/ob-standard-view-datasource.js	Mon Oct 07 17:17:08 2013 +0200
@@ -135,10 +135,23 @@
       if (isNewRecord && (operationType === 'update' || operationType === 'add')) {
         this.view._savingNewRecord = true;
       }
+      data = this.deleteNulls(data);
       this.Super('performDSOperation', [operationType, data, callback, newRequestProperties]);
     }
   },
 
+  deleteNulls: function (data) {
+    var column;
+    for (column in data) {
+      if (data.hasOwnProperty(column)) {
+        if (!data[column] && data[column] !== false && data[column] !== 0 && !this.view.viewForm.getFieldFromFieldName(column)) {
+          delete data[column];
+        }
+      }
+    }
+    return data;
+  },
+
   getAdditionalProps: function () {
     var prop, length, i, fld;
     if (this.additionalProps !== null) {
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/main/ob-standard-view.js	Mon Oct 07 15:22:32 2013 +0200
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/main/ob-standard-view.js	Mon Oct 07 17:17:08 2013 +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) 2010-2013 Openbravo SLU
+ * All portions are Copyright (C) 2010-2012 Openbravo SLU
  * All Rights Reserved.
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -2172,6 +2172,9 @@
   },
 
   setContextInfo: function (sessionProperties, callbackFunction, forced) {
+    var newCallback, me = this,
+        gridVisibleProperties = [],
+        len, i;
     // no need to set the context in this case
     if (!forced && (this.isEditingGrid || this.isShowingForm)) {
       if (callbackFunction) {
@@ -2181,15 +2184,39 @@
     }
 
     if (!sessionProperties) {
-      sessionProperties = this.getContextInfo(true, true, false, true);
+      // Call to the FIC in EDIT mode, all properties must be sent, not only the session properties
+      sessionProperties = this.getContextInfo(false, true, false, true);
+    }
+
+    newCallback = function (response, data, request) {
+      var context = {},
+          grid = me.viewGrid;
+      context.rowNum = grid.getRecordIndex(grid.getSelectedRecord());
+      context.grid = grid;
+      response.clientContext = context;
+      grid.processFICReturn(response, data, request);
+      if (callbackFunction) {
+        callbackFunction();
+      }
+    };
+
+    if (this.viewGrid && this.viewGrid.fields) {
+      gridVisibleProperties.push('id');
+      len = this.viewGrid.fields.length;
+      for (i = 0; i < len; i++) {
+        if (this.viewGrid.fields[i].name[0] !== '_') {
+          gridVisibleProperties.push(this.viewGrid.fields[i].name);
+        }
+      }
+      sessionProperties._gridVisibleProperties = gridVisibleProperties;
     }
 
     OB.RemoteCallManager.call('org.openbravo.client.application.window.FormInitializationComponent', sessionProperties, {
-      MODE: 'SETSESSION',
+      MODE: 'EDIT',
       TAB_ID: this.tabId,
       PARENT_ID: this.getParentId(),
       ROW_ID: this.viewGrid.getSelectedRecord() ? this.viewGrid.getSelectedRecord().id : this.getCurrentValues().id
-    }, callbackFunction);
+    }, newCallback);
 
   },
 
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/toolbar/ob-toolbar.js	Mon Oct 07 15:22:32 2013 +0200
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/toolbar/ob-toolbar.js	Mon Oct 07 17:17:08 2013 +0200
@@ -1247,7 +1247,7 @@
             theForm = this.view.isEditingGrid ? this.view.viewGrid.getEditForm() : this.view.viewForm,
             isNew = currentContext.viewForm.isNew,
             hideAllButtons = selectedRecords.size() === 0 && !currentContext.isShowingForm,
-            currentValues = currentContext.getCurrentValues();
+            currentValues = currentContext.getCurrentValues(), gridVisibleProperties = [], len;
 
         if (!hideAllButtons && (this.view.isEditingGrid || this.view.isShowingForm)) {
           hideAllButtons = theForm.hasErrors() || !theForm.allRequiredFieldsSet();
@@ -1281,6 +1281,15 @@
             requestParams.MULTIPLE_ROW_IDS = multipleSelectedRowIds;
           }
           allProperties = currentContext.getContextInfo(false, true, false, true);
+          if (currentContext.viewGrid && currentContext.viewGrid.fields) {
+            len = currentContext.viewGrid.fields.length;
+            for (i = 0; i < len; i++) {
+              if (currentContext.viewGrid.fields[i].name[0] !== '_') {
+                gridVisibleProperties.push(currentContext.viewGrid.fields[i].name);
+              }
+            }
+            allProperties._gridVisibleProperties = gridVisibleProperties;
+          }
           OB.RemoteCallManager.call('org.openbravo.client.application.window.FormInitializationComponent', allProperties, requestParams, callbackHandler(currentContext, me));
         } else {
           doRefresh(buttonsByContext[currentContext], currentValues || {}, hideAllButtons || noneOrMultipleRecordsSelected, numOfSelRecords !== 1, this);