[FIX] web: SampleServer: round float values
before this commit: when field is float type it display too much decimal precision value, it should be fixed to 2 precision for sample data. after this commit: float field will display 2 decimal precision value. task-2318503 closes odoo/odoo#63643 X-original-commit: 61f8ced67992b20edfac139c749ec00939f408a3 Signed-off-by: Aaron Bohy (aab) <aab@odoo.com> Co-authored-by: Kamesh Patel <kat@odoo.com>
This commit is contained in:
committed by
Aaron Bohy
co-authored by
Kamesh Patel
parent
b9c5ae27bb
commit
81f2bc7b0a
@@ -151,7 +151,7 @@ odoo.define('web.SampleServer', function (require) {
|
||||
for (const record of records) {
|
||||
value += record[fieldName];
|
||||
}
|
||||
values[fieldName] = value;
|
||||
values[fieldName] = this._sanitizeNumber(value);
|
||||
} else {
|
||||
values[fieldName] = null;
|
||||
}
|
||||
@@ -314,7 +314,7 @@ odoo.define('web.SampleServer', function (require) {
|
||||
* @returns {number} float in [O, max[
|
||||
*/
|
||||
_getRandomFloat(max) {
|
||||
return Math.random() * max;
|
||||
return this._sanitizeNumber(Math.random() * max);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -591,6 +591,16 @@ odoo.define('web.SampleServer', function (require) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Rounds the given number value according to the configured precision.
|
||||
* @private
|
||||
* @param {number} value
|
||||
* @returns {number}
|
||||
*/
|
||||
_sanitizeNumber(value) {
|
||||
return parseFloat(value.toFixed(SampleServer.FLOAT_PRECISION));
|
||||
}
|
||||
|
||||
/**
|
||||
* A real (web_)read_group call has been done, and it has returned groups,
|
||||
* but they are all empty. This function updates the sample data such
|
||||
@@ -653,6 +663,7 @@ odoo.define('web.SampleServer', function (require) {
|
||||
SampleServer.MAX_COLOR_INT = 7;
|
||||
SampleServer.MAX_MONETARY = 100000;
|
||||
SampleServer.DATE_DELTA = 24 * 60; // in hours -> 60 days
|
||||
SampleServer.FLOAT_PRECISION = 2;
|
||||
|
||||
SampleServer.SAMPLE_COUNTRIES = ["Belgium", "France", "Portugal", "Singapore", "Australia"];
|
||||
SampleServer.SAMPLE_PEOPLE = [
|
||||
|
||||
@@ -77,7 +77,7 @@ odoo.define('web.sample_server_tests', function (require) {
|
||||
QUnit.module("Basic behaviour");
|
||||
|
||||
QUnit.test("Sample data: people type + all field names", async function (assert) {
|
||||
assert.expect(24);
|
||||
assert.expect(25);
|
||||
|
||||
mock.patch(session, {
|
||||
company_currency_id: 4,
|
||||
@@ -134,6 +134,9 @@ odoo.define('web.sample_server_tests', function (require) {
|
||||
assertBetween('age', 0, MAX_INTEGER);
|
||||
assertBetween('salary', 0, MAX_MONETARY);
|
||||
|
||||
// check float field have 2 decimal rounding
|
||||
assert.strictEqual(rec.height, parseFloat(parseFloat(rec.height).toFixed(2)));
|
||||
|
||||
const selectionValues = this.fields['res.users'].type.selection.map(
|
||||
(sel) => sel[0]
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user