From 2e688daebd547f586c36174bfc680cfb5f44b0f3 Mon Sep 17 00:00:00 2001 From: "Laurent Mignon (ACSONE)" Date: Thu, 31 Oct 2019 15:08:47 +0100 Subject: [PATCH] [IMP] base_jsonify: Serialize Date and Datetime into ISO 8601 format --- base_jsonify/models/models.py | 4 ++-- base_jsonify/tests/test_get_parser.py | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/base_jsonify/models/models.py b/base_jsonify/models/models.py index 6fa32f90d..5d5c31a29 100644 --- a/base_jsonify/models/models.py +++ b/base_jsonify/models/models.py @@ -70,9 +70,9 @@ class Base(models.AbstractModel): if value is False and field_type != "boolean": value = None elif field_type == "date": - value = fields.Date.to_string(value) + value = fields.Date.to_date(value).isoformat() elif field_type == "datetime": - value = fields.Datetime.to_string(value) + value = fields.Datetime.to_datetime(value).isoformat() res[json_key] = value result.append(res) return result diff --git a/base_jsonify/tests/test_get_parser.py b/base_jsonify/tests/test_get_parser.py index 582d02aff..5aec2538e 100644 --- a/base_jsonify/tests/test_get_parser.py +++ b/base_jsonify/tests/test_get_parser.py @@ -79,7 +79,7 @@ class TestParser(TransactionCase): }, ) ], - "date": fields.Date.today(), + "date": fields.Date.from_string("2019-10-31"), } ) expected_json = { @@ -100,8 +100,8 @@ class TestParser(TransactionCase): "email": None, } ], - "create_date": fields.Datetime.to_string(partner.create_date), - "date": fields.Date.to_string(partner.date), + "create_date": partner.create_date.isoformat(), + "date": "2019-10-31", } json_partner = partner.jsonify(parser)