diff --git a/accounting/transport.py b/accounting/transport.py index 091791b14d72f63808b92dc84e0adef860b85d5f..72af3e5bc4928898362dd2c28e7abe60d3da5cfe 100644 --- a/accounting/transport.py +++ b/accounting/transport.py @@ -1,3 +1,5 @@ +from datetime import datetime + from flask import json from accounting import Amount, Transaction, Posting, Account @@ -30,6 +32,11 @@ class AccountingEncoder(json.JSONEncoder): amount=o.amount, symbol=o.symbol ) + elif isinstance(o, Exception): + return dict( + __type__=o.__class__.__name__, + args=o.args + ) return json.JSONEncoder.default(self, o) @@ -46,4 +53,7 @@ class AccountingDecoder(json.JSONDecoder): _type = d.pop('__type__') + if _type == 'Transaction': + d['date'] = datetime.strptime(d['date'], '%Y-%m-%d') + return types[_type](**d)