Skip to content

Commit

Permalink
Use simplejson Decimal support
Browse files Browse the repository at this point in the history
Modified imports and removed unused json imports
Modified calls to set use_decimal for serialization/deserialization
  • Loading branch information
laf-rge committed May 23, 2024
1 parent 827832c commit 5afd3f5
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 9 deletions.
4 changes: 2 additions & 2 deletions quickbooks/client.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import http.client as httplib
import textwrap
import json
import simplejson as json
import base64
import hashlib
import hmac
Expand Down Expand Up @@ -206,7 +206,7 @@ def make_request(self, request_type, url, request_body=None, content_type='appli
"Application authentication failed", error_code=req.status_code, detail=req.text)

try:
result = req.json()
result = json.loads(req.text, use_decimal=True)
except:
raise exceptions.QuickbooksException("Error reading json response: {0}".format(req.text), 10000)

Expand Down
10 changes: 4 additions & 6 deletions quickbooks/mixins.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
from urllib.parse import quote

try: import simplejson as json
except ImportError: import json
import simplejson as json

from .utils import build_where_clause, build_choose_clause
from .client import QuickBooks
from .exceptions import QuickbooksException


class ToJsonMixin(object):
def to_json(self):
return json.dumps(self, default=self.json_filter(), sort_keys=True, indent=4)
return json.dumps(self, default=self.json_filter(), sort_keys=True, indent=4, use_decimal=True)

def json_filter(self):
"""
Expand Down Expand Up @@ -178,7 +176,7 @@ def void(self, qb=None):

data = self.get_void_data()
params = self.get_void_params()
results = qb.post(url, json.dumps(data), params=params)
results = qb.post(url, json.dumps(data, use_decimal=True), params=params)

return results

Expand Down Expand Up @@ -232,7 +230,7 @@ def delete(self, qb=None, request_id=None):
'Id': self.Id,
'SyncToken': self.SyncToken,
}
return qb.delete_object(self.qbo_object_name, json.dumps(data), request_id=request_id)
return qb.delete_object(self.qbo_object_name, json.dumps(data, use_decimal=True), request_id=request_id)


class DeleteNoIdMixin(object):
Expand Down
1 change: 0 additions & 1 deletion quickbooks/objects/payment.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from ..client import QuickBooks
from .creditcardpayment import CreditCardPayment
from ..mixins import DeleteMixin, VoidMixin
import json


class PaymentLine(QuickbooksBaseObject):
Expand Down

0 comments on commit 5afd3f5

Please sign in to comment.