Skip to content

Commit

Permalink
handle Decimal on object values
Browse files Browse the repository at this point in the history
  • Loading branch information
laf-rge committed Aug 9, 2024
1 parent 045cded commit 248104f
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions quickbooks/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
from .utils import build_choose_clause, build_where_clause

class DecimalEncoder(json.JSONEncoder):
def default(self, obj):
if isinstance(obj, decimal.Decimal):
return str(obj)
return super(DecimalEncoder, self).default(obj)
def default(self, o):
if isinstance(o, decimal.Decimal):
return str(o)
return super(DecimalEncoder, self).default(o)

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


Expand Down

0 comments on commit 248104f

Please sign in to comment.