changeset 497c0f50732a in sao:default
details: https://hg.tryton.org/sao?cmd=changeset;node=497c0f50732a
description:
Encode Decimal with it primitive value for PYSON
Otherwise the Decimal is duplicated as a generic Object by the
preparation.
issue9852
review330001002
diffstat:
src/pyson.js | 2 ++
tests/sao.js | 4 ++++
2 files changed, 6 insertions(+), 0 deletions(-)
diffs (33 lines):
diff -r 631142760e94 -r 497c0f50732a src/pyson.js
--- a/src/pyson.js Wed Jan 06 11:00:07 2021 +0100
+++ b/src/pyson.js Mon Jan 11 00:11:25 2021 +0100
@@ -85,6 +85,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 631142760e94 -r 497c0f50732a tests/sao.js
--- a/tests/sao.js Wed Jan 06 11:00:07 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),