-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Question] Can we improve representation of Money
?
#297
Comments
In [3]: preauthorization.debited_funds
Out[3]: EUR 2495
In [4]: str(preauthorization.debited_funds)
Out[4]: 'EUR 2,495.00'
In [5]: vars(preauthorization.debited_funds)
Out[5]: {'amount': Decimal('2495'), 'currency': 'EUR'} But the correct number to show is In [6]: preauthorization.debited_funds.amount / 100
Out[6]: Decimal('24.95') or In [7]: preauthorization.debited_funds / 100
Out[7]: EUR 24.95 |
It is not always correct to divide by 100 because not all currencies have two decimals, see ISO 4217. In fact, there's no need to use
So the easiest option is to just use If you want to improve the |
In our project we are actually patching |
Not reason to not encapsulate this dance inside the SDK, I mean, mango.Money(amount=Decimal('10.10'), currency='EUR') means actually 0.10€ 😂 |
For example, I have Pay-In with the next data (screenshot from the dashboard):
When I check this Pay-In in the terminal I have:
From my point of view, these values should be represented as
EUR 180.43
andEUR 65.42
(as in the dashboard).To fix this I can suggest to use
self.amount / 100
instead ofself.amount
here:mangopay2-python-sdk/mangopay/utils.py
Lines 62 to 63 in 2a656a8
and here:
mangopay2-python-sdk/mangopay/utils.py
Lines 65 to 66 in 2a656a8
But of course, this "fix" will work only for the currencies with 2 digits after the decimal separator. So maybe there can be a better solution.
Also, I understand that
Money
in the SDK represents An amount of money in the smallest sub-division of the currency, so showing18043
instead of180.43
can be correct from some point of view. But we show currency near it and this can be confusing.But I think the minimum that can be done here is to use for
__str__
the same functionality as for__repr__
(means remove:,.2f
. For example, when I want to log Pay-In values I have something like next in my logs:As you can see, the
__str__
method is definitely produces an incorrect representation of the values from above.The text was updated successfully, but these errors were encountered: