From 248104f163b4be63e46b0677c76b164c6b1094ee Mon Sep 17 00:00:00 2001 From: "William N. Green" Date: Thu, 8 Aug 2024 19:03:56 -0700 Subject: [PATCH 1/3] handle Decimal on object values --- quickbooks/mixins.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/quickbooks/mixins.py b/quickbooks/mixins.py index c3b60d9..49db76f 100644 --- a/quickbooks/mixins.py +++ b/quickbooks/mixins.py @@ -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): @@ -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) From 91cc6d4c063c5e539e45903c081fa01f497bdd78 Mon Sep 17 00:00:00 2001 From: "William N. Green" Date: Sun, 12 Jan 2025 15:03:24 -0800 Subject: [PATCH 2/3] Added simple test for decimal amounts in Bill --- tests/unit/test_decimal.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 tests/unit/test_decimal.py diff --git a/tests/unit/test_decimal.py b/tests/unit/test_decimal.py new file mode 100644 index 0000000..77fecca --- /dev/null +++ b/tests/unit/test_decimal.py @@ -0,0 +1,21 @@ +from decimal import Decimal +import unittest +from quickbooks.objects.bill import Bill +from quickbooks.objects.detailline import DetailLine + + +class DecimalTestCase(unittest.TestCase): + def test_bill_with_decimal_amount(self): + """Test that a Bill with decimal line amounts can be converted to JSON without errors""" + bill = Bill() + line = DetailLine() + line.Amount = Decimal('42.42') + line.DetailType = "AccountBasedExpenseLineDetail" + + bill.Line.append(line) + + # This should not raise any exceptions + json_data = bill.to_json() + + # Verify the amount was converted correctly + self.assertIn('"Amount": "42.42"', json_data) From c61efc8d5819a055e281f2c32d7471afeea1a7c9 Mon Sep 17 00:00:00 2001 From: "William N. Green" Date: Mon, 13 Jan 2025 08:08:18 -0800 Subject: [PATCH 3/3] removed python 3.7 and added 3.13 --- .github/workflows/python-package.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index fcb126c..804cd82 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -16,7 +16,7 @@ jobs: strategy: fail-fast: false matrix: - python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12"] + python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"] steps: - uses: actions/checkout@v3