Fixes Issue 0025517: Wrong calculations on numeric field depending on the formula
authorShankar Balachandran <shankar.balachandran@openbravo.com>
Wed, 05 Mar 2014 11:28:14 +0530
changeset 22345 381047f42270
parent 22344 94e3b048685e
child 22346 b80b24804395
Fixes Issue 0025517: Wrong calculations on numeric field depending on the formula

Formatting of the number is done after evaluation of the math expression.
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	Tue Mar 04 20:54:42 2014 +0530
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/formitem/ob-formitem-number.js	Wed Mar 05 11:28:14 2014 +0530
@@ -433,7 +433,12 @@
 
     // Make sure the number is rounded using the number of decimal digits specified in the number typeInstance
     if (isc.isA.String(this.getValue())) {
-      value = OB.Utilities.Number.OBPlainToOBMasked(this.getValue(), this.typeInstance.maskNumeric, this.typeInstance.decSeparator, this.typeInstance.groupSeparator);
+      //if the string is a math expression do not perform rounding yet.
+      if (this.getValue().indexOf('=') === -1) {
+        value = OB.Utilities.Number.OBPlainToOBMasked(this.getValue(), this.typeInstance.maskNumeric, this.typeInstance.decSeparator, this.typeInstance.groupSeparator);
+      } else {
+        value = this.getValue();
+      }
       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);
@@ -461,7 +466,8 @@
 
       // first check if the number is valid
       if (!isc.isA.String(value)) {
-        // format the value displayed
+        // format the value to be displayed.
+        value = OB.Utilities.Number.OBPlainToOBMasked(this.getValue(), this.typeInstance.maskNumeric, this.typeInstance.decSeparator, this.typeInstance.groupSeparator);
         this.setElementValue(this.mapValueToDisplay(value));
       }
     }