Skip to content

Commit 248104f

Browse files
committed
handle Decimal on object values
1 parent 045cded commit 248104f

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

quickbooks/mixins.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
from .utils import build_choose_clause, build_where_clause
88

99
class DecimalEncoder(json.JSONEncoder):
10-
def default(self, obj):
11-
if isinstance(obj, decimal.Decimal):
12-
return str(obj)
13-
return super(DecimalEncoder, self).default(obj)
10+
def default(self, o):
11+
if isinstance(o, decimal.Decimal):
12+
return str(o)
13+
return super(DecimalEncoder, self).default(o)
1414

1515
class ToJsonMixin(object):
1616
def to_json(self):
@@ -21,7 +21,7 @@ def json_filter(self):
2121
filter out properties that have names starting with _
2222
or properties that have a value of None
2323
"""
24-
return lambda obj: dict((k, v) for k, v in obj.__dict__.items()
24+
return lambda obj: str(obj) if isinstance(obj, decimal.Decimal) else dict((k, v) for k, v in obj.__dict__.items()
2525
if not k.startswith('_') and getattr(obj, k) is not None)
2626

2727

0 commit comments

Comments
 (0)