Browse Source

[FIX] base_jsonify: Add tz info into serialized datetime

13.0
Laurent Mignon (ACSONE) 5 years ago
parent
commit
e868810b6f
  1. 2
      .isort.cfg
  2. 8
      base_jsonify/models/models.py
  3. 7
      base_jsonify/tests/test_get_parser.py

2
.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=setuptools
known_third_party=pytz,setuptools

8
base_jsonify/models/models.py

@ -3,6 +3,8 @@
# Raphaël Reverdy <raphael.reverdy@akretion.com>
# 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 _
@ -72,7 +74,11 @@ 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).isoformat()
value = (
fields.Datetime.to_datetime(value)
.replace(tzinfo=pytz.utc)
.isoformat()
)
res[json_key] = value
result.append(res)
return result

7
base_jsonify/tests/test_get_parser.py

@ -82,6 +82,11 @@ class TestParser(TransactionCase):
"date": fields.Date.from_string("2019-10-31"),
}
)
# put our own create date to ease tests
self.env.cr.execute(
"update res_partner set create_date=%s where id=%s",
("2019-10-31 14:39:49", partner.id),
)
expected_json = {
"lang": "en_US",
"comment": None,
@ -100,7 +105,7 @@ class TestParser(TransactionCase):
"email": None,
}
],
"create_date": partner.create_date.isoformat(),
"create_date": "2019-10-31T14:39:49+00:00",
"date": "2019-10-31",
}
json_partner = partner.jsonify(parser)

Loading…
Cancel
Save