|
| 1 | +import decimal |
| 2 | +import json |
1 | 3 | from urllib.parse import quote |
2 | 4 |
|
3 | | -try: import simplejson as json |
4 | | -except ImportError: import json |
5 | | - |
6 | | -from .utils import build_where_clause, build_choose_clause |
7 | 5 | from .client import QuickBooks |
8 | 6 | from .exceptions import QuickbooksException |
| 7 | +from .utils import build_choose_clause, build_where_clause |
9 | 8 |
|
| 9 | +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 | 14 |
|
11 | 15 | class ToJsonMixin(object): |
12 | 16 | def to_json(self): |
13 | | - return json.dumps(self, default=self.json_filter(), sort_keys=True, indent=4) |
| 17 | + return json.dumps(self, cls=DecimalEncoder, default=self.json_filter(), sort_keys=True, indent=4) |
14 | 18 |
|
15 | 19 | def json_filter(self): |
16 | 20 | """ |
@@ -178,7 +182,7 @@ def void(self, qb=None): |
178 | 182 |
|
179 | 183 | data = self.get_void_data() |
180 | 184 | params = self.get_void_params() |
181 | | - results = qb.post(url, json.dumps(data), params=params) |
| 185 | + results = qb.post(url, json.dumps(data, cls=DecimalEncoder), params=params) |
182 | 186 |
|
183 | 187 | return results |
184 | 188 |
|
@@ -232,7 +236,7 @@ def delete(self, qb=None, request_id=None): |
232 | 236 | 'Id': self.Id, |
233 | 237 | 'SyncToken': self.SyncToken, |
234 | 238 | } |
235 | | - return qb.delete_object(self.qbo_object_name, json.dumps(data), request_id=request_id) |
| 239 | + return qb.delete_object(self.qbo_object_name, json.dumps(data, cls=DecimalEncoder), request_id=request_id) |
236 | 240 |
|
237 | 241 |
|
238 | 242 | class DeleteNoIdMixin(object): |
|
0 commit comments