Browse Source

Merge PR #1715 into 13.0

Signed-off-by moylop260
13.0
OCA-git-bot 5 years ago
parent
commit
4950d01f85
  1. 10
      base_jsonify/models/models.py
  2. 13
      base_jsonify/tests/test_get_parser.py

10
base_jsonify/models/models.py

@ -70,9 +70,15 @@ 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)
# 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
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",
@ -79,9 +81,14 @@ class TestParser(TransactionCase):
},
)
],
"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,
@ -100,8 +107,8 @@ class TestParser(TransactionCase):
"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)

Loading…
Cancel
Save