Fix protocoin current balance floating point precision bug

This commit is contained in:
Tanner Collin 2023-04-27 01:36:57 +00:00
parent 9224c546a9
commit ef6cefe9aa

View File

@ -1190,7 +1190,7 @@ class ProtocoinViewSet(Base):
source_user_balance = source_user.transactions.aggregate(Sum('protocoin'))['protocoin__sum'] or 0 source_user_balance = source_user.transactions.aggregate(Sum('protocoin'))['protocoin__sum'] or 0
source_user_balance = float(source_user_balance) source_user_balance = float(source_user_balance)
if source_user_balance != balance: if abs(source_user_balance - balance) > 0.01: # stupid https://docs.djangoproject.com/en/4.2/ref/databases/#decimal-handling
raise exceptions.ValidationError(dict(balance='Incorrect current balance.')) raise exceptions.ValidationError(dict(balance='Incorrect current balance.'))
if source_user_balance < amount: if source_user_balance < amount:
@ -1324,7 +1324,7 @@ class ProtocoinViewSet(Base):
source_user_balance = source_user.transactions.aggregate(Sum('protocoin'))['protocoin__sum'] or 0 source_user_balance = source_user.transactions.aggregate(Sum('protocoin'))['protocoin__sum'] or 0
source_user_balance = float(source_user_balance) source_user_balance = float(source_user_balance)
if source_user_balance != balance: if abs(source_user_balance - balance) > 0.01: # stupid https://docs.djangoproject.com/en/4.2/ref/databases/#decimal-handling
raise exceptions.ValidationError(dict(balance='Incorrect current balance.')) raise exceptions.ValidationError(dict(balance='Incorrect current balance.'))
if source_user_balance < amount: if source_user_balance < amount: