details:   https://code.openbravo.com/erp/devel/pi/rev/39b9171de017
changeset: 25756:39b9171de017
user:      Augusto Mauch <augusto.mauch <at> openbravo.com>
date:      Mon Jan 26 12:39:25 2015 +0100
summary:   Fixes bug 28747,related with bug 28427: Number entered with formula 
is rounded

The problem was that if a number was entered using a formula (i.e. by entering 
=1/3 in the form item), the value was not rounded using the numeric field mask. 
For non-formula inputs the validation is done at the beginning of the blur 
function. For formula inputs it is not possible to do it at that point, because 
the value of the field is still the formula, not the result of evaluating the 
formula. The formula is evaluated in the validate function(), so the rounding 
for formula inputs is done after invoking it.

diffstat:

 
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/formitem/ob-formitem-number.js
 |  20 +++++++--
 1 files changed, 15 insertions(+), 5 deletions(-)

diffs (64 lines):

diff -r ad079bdad031 -r 39b9171de017 
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/formitem/ob-formitem-number.js
--- 
a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/formitem/ob-formitem-number.js
      Mon Jan 26 10:04:44 2015 +0100
+++ 
b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/formitem/ob-formitem-number.js
      Mon Jan 26 12:39:25 2015 +0100
@@ -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) 2011-2013 Openbravo SLU
+ * All portions are Copyright (C) 2011-2015 Openbravo SLU
  * All Rights Reserved.
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -429,7 +429,7 @@
   },
 
   blur: function () {
-    var value, roundedValue, textRoundedValue;
+    var value, roundedValue, textRoundedValue, isFormula = false;
 
     // Make sure the number is rounded using the number of decimal digits 
specified in the number typeInstance
     if (isc.isA.String(this.getValue())) {
@@ -438,14 +438,15 @@
         value = OB.Utilities.Number.OBPlainToOBMasked(this.getValue(), 
this.typeInstance.maskNumeric, this.typeInstance.decSeparator, 
this.typeInstance.groupSeparator, OB.Format.defaultGroupingSize);
       } else {
         value = this.getValue();
+        isFormula = true;
       }
       this.setValue(OB.Utilities.Number.OBMaskedToJS(value, 
this.typeInstance.decSeparator, this.typeInstance.groupSeparator));
       if (this.form.setTextualValue) {
         this.form.setTextualValue(this.name, value, this.typeInstance);
       }
     } else {
-      value = OB.Utilities.Number.JSToOBMasked(this.getValue(), 
this.typeInstance.maskNumeric, this.typeInstance.decSeparator, 
this.typeInstance.groupSeparator);
-      this.setValue(OB.Utilities.Number.OBMaskedToJS(value,  
this.typeInstance.decSeparator, this.typeInstance.groupSeparator));
+      value = this.roundJsNumberUsingTypeInstance(this.getValue(), 
this.typeInstance);
+      this.setValue(value);
     }
 
     if (this.grid && this.grid.isEditing && this.grid.isEditing()) {
@@ -466,7 +467,11 @@
       this.validate();
 
       value = this.getValue();
-
+      if (isFormula) {
+        // the formula is evaluated in the validate function, so until then it 
is not possible to round it, do it now
+        value = this.roundJsNumberUsingTypeInstance(value, this.typeInstance);
+        this.setValue(value);
+      }
       // first check if the number is valid
       if (!isc.isA.String(value)) {
         // format the value to be displayed.
@@ -475,6 +480,11 @@
       }
     }
     return this.Super('blur', arguments);
+  },
+
+  roundJsNumberUsingTypeInstance: function (jsNumber, typeInstance) {
+    var roundedStringNumber = OB.Utilities.Number.JSToOBMasked(jsNumber, 
typeInstance.maskNumeric, typeInstance.decSeparator, 
typeInstance.groupSeparator);
+    return OB.Utilities.Number.OBMaskedToJS(roundedStringNumber, 
typeInstance.decSeparator, typeInstance.groupSeparator);
   }
 });
 

------------------------------------------------------------------------------
Dive into the World of Parallel Programming. The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net/
_______________________________________________
Openbravo-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to