Skip to content

Commit

Permalink
Merge PR #1714 into 12.0
Browse files Browse the repository at this point in the history
Signed-off-by moylop260
  • Loading branch information
OCA-git-bot committed Nov 1, 2019
2 parents feae1f6 + b5543b6 commit c09a318
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
10 changes: 8 additions & 2 deletions base_jsonify/models/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,15 @@ 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)
# 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
13 changes: 10 additions & 3 deletions base_jsonify/tests/test_get_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ def test_getting_parser(self):
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',
Expand Down Expand Up @@ -70,8 +72,13 @@ def test_json_export(self):
'country_id': self.env.ref('base.fr').id
})
],
'date': fields.Date.today()
'date': fields.Date.from_string("2019-10-31")
})
self.env.cr.execute(
"update res_partner set create_date=%s where id=%s",
("2019-10-31 14:39:49", partner.id),
)
partner.refresh()
expected_json = {
'lang': 'en_US',
'comment': None,
Expand All @@ -96,8 +103,8 @@ def test_json_export(self):
'name': 'Sebatien Beau',
'email': None
}],
'create_date': fields.Datetime.to_string(partner.create_date),
'date': fields.Date.to_string(partner.date)
"create_date": "2019-10-31T15:39:49+01:00",
"date": "2019-10-31",
}
json_partner = partner.jsonify(parser)

Expand Down

0 comments on commit c09a318

Please sign in to comment.