Convert to Using Decimal and Fix Related Test#356
Merged
ej2 merged 5 commits intoej2:masterfrom Jul 9, 2024
Merged
Conversation
Modified imports and removed unused json imports Modified calls to set use_decimal for serialization/deserialization
laf-rge
commented
May 23, 2024
tests/unit/test_client.py
Outdated
| def content(self): | ||
| return '' | ||
|
|
||
| class MockResponseSimpleJson: |
Contributor
Author
There was a problem hiding this comment.
I was not sure why MockResponse had set the text field in the way that it did, so I created my own mock object that replaces it for the test that needed text to provide a valid json string.
laf-rge
commented
May 23, 2024
| from ..client import QuickBooks | ||
| from .creditcardpayment import CreditCardPayment | ||
| from ..mixins import DeleteMixin, VoidMixin | ||
| import json |
Merged
Put the decode on the test, removed the name for clarity
Contributor
Author
|
Added toggle to enable the decoding to decimals as per @justmobilize suggestion |
pablogamboa
approved these changes
Jun 3, 2024
ej2
approved these changes
Jul 9, 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request changes the datatype returned from the library to Decimal where floats are returned in the current version.
Rationale:
Using Decimal ensures precise handling of financial data, which is critical for the integrity of financial applications. The json library provides support through parse_float on decode and a helper cls for encoding. I have used a monkeypatched version and decided to contribute a clean version upstream. Here is what I did:
Convert to Using Decimal with json:
UPDATE:
Changed json parsing and added a decimaldecorder helper to seamlessly convert into and out of Decimal type when encoding an decoding json.
Update Tests:
Modified the existing tests to align with the changes introduced.
Specifically, fixed the test_make_request to ensure compatibility with handling of Decimal.
Changes Made:
Test Fix:
Testing:
Manual Testing: Conducted manual testing to ensure that the changes do not introduce any regressions.
Additional Notes:
Backward Compatibility: This change could break other projects that expect the amounts to be in floats, expecially if they are serializing the data. In general, however, Decimals work almost everywhere in python where floats work and I think anyone doing maths for currencies have, like me, been converting to Decimal all along anyway.
Documentation: No changes have been made yet I wanted to get feedback first before investing more time.