Openbravo Issue Tracking System - Openbravo ERP |
View Issue Details |
|
ID | Project | Category | View Status | Date Submitted | Last Update |
0029113 | Openbravo ERP | A. Platform | public | 2015-03-03 16:37 | 2015-03-06 16:04 |
|
Reporter | jecharri | |
Assigned To | AugustoMauch | |
Priority | immediate | Severity | minor | Reproducibility | always |
Status | closed | Resolution | fixed | |
Platform | | OS | 5 | OS Version | |
Product Version | pi | |
Target Version | 3.0PR15Q2 | Fixed in Version | 3.0PR15Q2 | |
Merge Request Status | |
Review Assigned To | dbaz |
OBNetwork customer | |
Web browser | |
Modules | Core |
Support ticket | |
Regression level | |
Regression date | |
Regression introduced in release | |
Regression introduced by commit | |
Triggers an Emergency Pack | No |
|
Summary | 0029113: Openbravo interface is not rounding properly the database data |
Description | Openbravo interface is not rounding properly the database data |
Steps To Reproduce | Simplified version:
- Execute this in the javascript console:
OB.Utilities.Number.roundJSNumber(0.135, 2); // it returns 0.14, that is OK
OB.Utilities.Number.roundJSNumber(0.145, 2); // it returns 0.14, that is WRONG
====================
To see how to reproduce it using the UI, follow these steps:
- Open Sales Order
- Create a header and save it
- Create a line.
- Enter 0.135 in the Net Unit Price field and press tab. The price is roudned to 0.14, this is OK
- Enter 0.145 in the Net Unit Price field and press tab. The price is roudned to 0.14, this is WRONG |
Proposed Solution | |
Additional Information | |
Tags | No tags attached. |
Relationships | related to | defect | 0029139 | | new | marvintm | Retail Modules | Web POS shouldn't import javascript resources from Core | related to | defect | 0030014 | | closed | NaroaIriarte | Openbravo ERP | The function OB.Utilities.Number.OBMaskedToOBPlain is not working properly with negative big numbers |
|
Attached Files | |
|
Issue History |
Date Modified | Username | Field | Change |
2015-03-03 16:37 | jecharri | New Issue | |
2015-03-03 16:37 | jecharri | Assigned To | => AugustoMauch |
2015-03-03 16:37 | jecharri | Modules | => Core |
2015-03-03 16:37 | jecharri | Resolution time | => 1425423600 |
2015-03-03 16:37 | jecharri | Triggers an Emergency Pack | => No |
2015-03-03 16:41 | AugustoMauch | Steps to Reproduce Updated | bug_revision_view_page.php?rev_id=7830#r7830 |
2015-03-03 16:42 | AugustoMauch | Steps to Reproduce Updated | bug_revision_view_page.php?rev_id=7831#r7831 |
2015-03-03 16:44 | AugustoMauch | Note Added: 0075130 | |
2015-03-03 17:32 | AugustoMauch | Note Edited: 0075130 | bug_revision_view_page.php?bugnote_id=0075130#r7833 |
2015-03-04 04:36 | johnfandl | Issue Monitored: johnfandl | |
2015-03-04 04:37 | johnfandl | Note Added: 0075137 | |
2015-03-04 09:14 | AugustoMauch | Issue Monitored: dbaz | |
2015-03-04 09:14 | AugustoMauch | Review Assigned To | => dbaz |
2015-03-04 09:17 | hgbot | Checkin | |
2015-03-04 09:17 | hgbot | Note Added: 0075138 | |
2015-03-04 09:17 | hgbot | Status | new => resolved |
2015-03-04 09:17 | hgbot | Resolution | open => fixed |
2015-03-04 09:17 | hgbot | Fixed in SCM revision | => http://code.openbravo.com/erp/devel/pi/rev/b5096788cd44794964e99024d9b19a5c86efa2f4 [^] |
2015-03-04 09:19 | AugustoMauch | Note Added: 0075139 | |
2015-03-04 09:21 | AugustoMauch | Steps to Reproduce Updated | bug_revision_view_page.php?rev_id=7836#r7836 |
2015-03-04 15:51 | hudsonbot | Checkin | |
2015-03-04 15:51 | hudsonbot | Note Added: 0075160 | |
2015-03-04 19:37 | dbaz | Note Added: 0075177 | |
2015-03-04 19:37 | dbaz | Status | resolved => new |
2015-03-04 19:37 | dbaz | Resolution | fixed => open |
2015-03-05 00:56 | Orekaria | Note Added: 0075183 | |
2015-03-05 00:56 | Orekaria | Note Edited: 0075183 | bug_revision_view_page.php?bugnote_id=0075183#r7858 |
2015-03-05 10:17 | hgbot | Checkin | |
2015-03-05 10:17 | hgbot | Note Added: 0075187 | |
2015-03-05 10:17 | hgbot | Status | new => resolved |
2015-03-05 10:17 | hgbot | Resolution | open => fixed |
2015-03-05 10:17 | hgbot | Fixed in SCM revision | http://code.openbravo.com/erp/devel/pi/rev/b5096788cd44794964e99024d9b19a5c86efa2f4 [^] => http://code.openbravo.com/erp/devel/pi/rev/e9d73be9949d975d17c8db516b0104a9d868b51f [^] |
2015-03-05 10:46 | AugustoMauch | Relationship added | related to 0029139 |
2015-03-05 10:50 | hgbot | Checkin | |
2015-03-05 10:50 | hgbot | Note Added: 0075188 | |
2015-03-05 11:54 | dbaz | Note Added: 0075190 | |
2015-03-05 11:54 | dbaz | Status | resolved => closed |
2015-03-05 11:54 | dbaz | Fixed in Version | => 3.0PR15Q2 |
2015-03-05 17:01 | hudsonbot | Checkin | |
2015-03-05 17:01 | hudsonbot | Note Added: 0075212 | |
2015-03-06 16:04 | hudsonbot | Checkin | |
2015-03-06 16:04 | hudsonbot | Note Added: 0075253 | |
2015-05-26 13:21 | NaroaIriarte | Relationship added | blocks 0030014 |
2015-05-26 15:17 | NaroaIriarte | Relationship replaced | related to 0030014 |
Notes |
|
(0075130)
|
AugustoMauch
|
2015-03-03 16:44
(edited on: 2015-03-03 17:32) |
|
The issue is caused by a javascript rounding problem. The OB.Utilities.Number.roundJSNumber(num, dec) functions does this:
result = Math.round(num * Math.pow(10, dec)) / Math.pow(10, dec);
0.135*Math.pow(10, 2) returns 13.5, that is OK
0.145*Math.pow(10, 2) returns 14.499999999999998, that is WRONG (it should return 14.5)
|
|
|
|
|
|
(0075138)
|
hgbot
|
2015-03-04 09:17
|
|
Repository: erp/devel/pi
Changeset: b5096788cd44794964e99024d9b19a5c86efa2f4
Author: Augusto Mauch <augusto.mauch <at> openbravo.com>
Date: Tue Mar 03 19:14:50 2015 +0100
URL: http://code.openbravo.com/erp/devel/pi/rev/b5096788cd44794964e99024d9b19a5c86efa2f4 [^]
Fixes issue 29113: BigDecimal is used to prevent rounding error
There was a problem with javascript decimal precision that was affecting the way we round numbers using the OB.Utilities.Number.roundJSNumber. For instance, if this is 0.145*100 is evaluated in the javascr
ipt console, the result was 14.499999999999998, not 14.5.
Now the OB.Utilities.Number.roundJSNumber uses BigDecimal to overcome this precision error. This is the command used not to round a number:
parseFloat(new BigDecimal(num).round(dec,BigDecimal.prototype.ROUND_HALF_UP));
---
M modules/org.openbravo.client.application/web/org.openbravo.client.application/js/utilities/ob-utilities-number.js
---
|
|
|
|
Tested in ci.openbravo.com/view/try/ with success |
|
|
|
|
|
(0075177)
|
dbaz
|
2015-03-04 19:37
|
|
While evaluating:
isNaN(OB.Utilities.Number.roundJSNumber('not_a_number', 2));
before the fix the result was: true
after the fix the result is: Uncaught BigDecimal(): Not a number: n,o,t,_,a,_,n,u,m,b,e,r
There are two possible ways to handle with this situation:
a) Declare the changeset as an API change
b) Add in the beginning some code like:
if (isNaN(parseInt(num, 10))) {
return parseInt(num, 10);
}
with this you ensure that before and after the changeset, both functions return the same in case of passing a bad number
I am more in favour of something like option "b", because you avoid the API change and you can track easily if the returned item is not a number. |
|
|
|
|
|
(0075187)
|
hgbot
|
2015-03-05 10:17
|
|
Repository: erp/devel/pi
Changeset: e9d73be9949d975d17c8db516b0104a9d868b51f
Author: Augusto Mauch <augusto.mauch <at> openbravo.com>
Date: Thu Mar 05 10:15:41 2015 +0100
URL: http://code.openbravo.com/erp/devel/pi/rev/e9d73be9949d975d17c8db516b0104a9d868b51f [^]
Fixes issue 29113: Use setScale instead of round, and handle properly NaN
The BigDecimal.round function did not work as we expected [1]:
new BigDecimal('0.145').round(2, BigDecimal.prototype.ROUND_HALF_UP).toString() -> 0.15 (OK)
new BigDecimal('1.145').round(2, BigDecimal.prototype.ROUND_HALF_UP).toString() -> 1.1 (WRONG)
new BigDecimal('10.145').round(2, BigDecimal.prototype.ROUND_HALF_UP).toString() -> 10 (WRONG)
To round the number to a specific amout of decimal digits, the setScale function should be used.
new BigDecimal('0.145').setScale(2, BigDecimal.prototype.ROUND_HALF_UP).toString() -> 0.15 (OK)
new BigDecimal('1.145').setScale(2, BigDecimal.prototype.ROUND_HALF_UP).toString() -> 1.15 (OK)
new BigDecimal('10.145').setScale(2, BigDecimal.prototype.ROUND_HALF_UP).toString() -> 10.15 (OK)
Also, when the number provided in the first argument of the OB.Utilities.Number.roundJSNumber is not a number, the function returns NaN, as it used to do it before.
[1] http://stackoverflow.com/a/13461270 [^]
---
M modules/org.openbravo.client.application/web/org.openbravo.client.application/js/utilities/ob-utilities-number.js
---
|
|
|
(0075188)
|
hgbot
|
2015-03-05 10:50
|
|
Repository: erp/devel/pi
Changeset: 1c75a6afca4e9a09fa5593a2a22b56f6e83fdb6a
Author: Augusto Mauch <augusto.mauch <at> openbravo.com>
Date: Thu Mar 05 10:49:36 2015 +0100
URL: http://code.openbravo.com/erp/devel/pi/rev/1c75a6afca4e9a09fa5593a2a22b56f6e83fdb6a [^]
Related with issue 29113: Avoid using isc in OB.Utilities.Number.roundJSNumber
The OB.Utilities.Number.roundJSNumber function is used in the mobile core module, but smartclient is not available there. OB.Utilities.Number.roundJSNumber should not be used there (see [1]), but in the meantime we are going to avoid using smartclient functions in roundJSNumber.
isc.isA.String has been replaced with (typeof num === 'string')
[1] https://issues.openbravo.com/view.php?id=29139 [^]
---
M modules/org.openbravo.client.application/web/org.openbravo.client.application/js/utilities/ob-utilities-number.js
---
|
|
|
(0075190)
|
dbaz
|
2015-03-05 11:54
|
|
Reviewed @ changeset: 26127 - 1c75a6afca4e |
|
|
|
|
|
|
|