diff --git a/.isort.cfg b/.isort.cfg index da6da63fd..98b216f74 100644 --- a/.isort.cfg +++ b/.isort.cfg @@ -9,4 +9,4 @@ line_length=88 known_odoo=odoo known_odoo_addons=odoo.addons sections=FUTURE,STDLIB,THIRDPARTY,ODOO,ODOO_ADDONS,FIRSTPARTY,LOCALFOLDER -known_third_party=pytz,setuptools +known_third_party=setuptools diff --git a/base_jsonify/models/models.py b/base_jsonify/models/models.py index 24ad417f0..195eb9e17 100644 --- a/base_jsonify/models/models.py +++ b/base_jsonify/models/models.py @@ -3,8 +3,6 @@ # Raphaƫl Reverdy # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -import pytz - from odoo import api, fields, models from odoo.exceptions import UserError from odoo.tools.translate import _ @@ -74,11 +72,13 @@ class Base(models.AbstractModel): elif field_type == "date": value = fields.Date.to_date(value).isoformat() elif field_type == "datetime": - value = ( - fields.Datetime.to_datetime(value) - .replace(tzinfo=pytz.utc) - .isoformat() - ) + # Ensures value is a datetime + value = fields.Datetime.to_datetime(value) + # Get the timestamp converted to the client's timezone. + # This call also add the tzinfo into the datetime + # object + value = fields.Datetime.context_timestamp(rec, value) + value = 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 a27fb720a..9c9b79a32 100644 --- a/base_jsonify/tests/test_get_parser.py +++ b/base_jsonify/tests/test_get_parser.py @@ -41,6 +41,8 @@ class TestParser(TransactionCase): self.assertEqual(parser, expected_parser) def test_json_export(self): + # Enforces TZ to validate the serialization result of a Datetime + self.env.user.tz = "Europe/Brussels" parser = [ "lang", "comment", @@ -105,7 +107,7 @@ class TestParser(TransactionCase): "email": None, } ], - "create_date": "2019-10-31T14:39:49+00:00", + "create_date": "2019-10-31T15:39:49+01:00", "date": "2019-10-31", } json_partner = partner.jsonify(parser)