Skip to content

Commit

Permalink
Merge e868810 into d010a0e
Browse files Browse the repository at this point in the history
  • Loading branch information
lmignon committed Oct 31, 2019
2 parents d010a0e + e868810 commit 409bb41
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .isort.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 8 additions & 2 deletions base_jsonify/models/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 _
Expand Down Expand Up @@ -70,9 +72,13 @@ def jsonify(self, parser):
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)
.replace(tzinfo=pytz.utc)
.isoformat()
)
res[json_key] = value
result.append(res)
return result
11 changes: 8 additions & 3 deletions base_jsonify/tests/test_get_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,14 @@ def test_json_export(self):
},
)
],
"date": fields.Date.today(),
"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,
Expand All @@ -100,8 +105,8 @@ def test_json_export(self):
"email": None,
}
],
"create_date": fields.Datetime.to_string(partner.create_date),
"date": fields.Date.to_string(partner.date),
"create_date": "2019-10-31T14:39:49+00:00",
"date": "2019-10-31",
}
json_partner = partner.jsonify(parser)

Expand Down

0 comments on commit 409bb41

Please sign in to comment.