changeset 28bbd53f524b in sao:5.8
details: https://hg.tryton.org/sao?cmd=changeset;node=28bbd53f524b
description:
Encode Decimal with it primitive value for PYSON
Otherwise the Decimal is duplicated as a generic Object by the
preparation.
issue9852
review330001002
(grafted from 497c0f50732acac30b99177a22b454c626fe4334)
diffstat:
src/pyson.js | 2 ++
tests/sao.js | 4 ++++
2 files changed, 6 insertions(+), 0 deletions(-)
diffs (33 lines):
diff -r f07512732ec3 -r 28bbd53f524b src/pyson.js
--- a/src/pyson.js Tue Jan 05 11:59:43 2021 +0100
+++ b/src/pyson.js Mon Jan 11 00:11:25 2021 +0100
@@ -82,6 +82,8 @@
value.seconds(),
value.milliseconds() * 1000).pyson();
}
+ } else if (value instanceof Sao.Decimal) {
+ value = value.valueOf();
} else if ((value instanceof Object) &&
!(value instanceof Sao.PYSON.PYSON)) {
value = jQuery.extend({}, value);
diff -r f07512732ec3 -r 28bbd53f524b tests/sao.js
--- a/tests/sao.js Tue Jan 05 11:59:43 2021 +0100
+++ b/tests/sao.js Mon Jan 11 00:11:25 2021 +0100
@@ -45,6 +45,8 @@
QUnit.test('PYSON Encoder', function() {
var encoder = new Sao.PYSON.Encoder();
var none;
+ var decimal = Sao.Decimal(1.1);
+ var pyson_decimal = 1.1;
var date = Sao.Date(2002, 0, 1);
var datetime = Sao.DateTime(2002, 0, 1, 12, 30, 0, 0);
var pyson_date = new Sao.PYSON.Date(2002, 1, 1).pyson();
@@ -63,6 +65,8 @@
QUnit.strictEqual(encoder.encode(), 'null', "encode()");
QUnit.strictEqual(encoder.encode(none), 'null', "encode(none)");
QUnit.strictEqual(encoder.encode(null), 'null', "encode()");
+ QUnit.strictEqual(encoder.encode(decimal),
+ JSON.stringify(pyson_decimal), "encode(decimal)");
QUnit.strictEqual(encoder.encode(date),
JSON.stringify(pyson_date), "encode(date)");
QUnit.strictEqual(encoder.encode(datetime),