| Line 6055... |
Line 6055... |
| 6055 |
"""To only reverse wallet payments, check add_amount_in_wallet to add new amount"""
|
6055 |
"""To only reverse wallet payments, check add_amount_in_wallet to add new amount"""
|
| 6056 |
|
6056 |
|
| 6057 |
if amount <= 0 or WalletReferenceType._VALUES_TO_NAMES.get(reference_type) is None:
|
6057 |
if amount <= 0 or WalletReferenceType._VALUES_TO_NAMES.get(reference_type) is None:
|
| 6058 |
return
|
6058 |
return
|
| 6059 |
|
6059 |
|
| 6060 |
history = None
|
6060 |
previous_debit_history = None
|
| 6061 |
if reference_type==WalletReferenceType.RECHARGE:
|
6061 |
if reference_type==WalletReferenceType.RECHARGE:
|
| 6062 |
history = UserWalletHistory.query.filter_by(reference = reference).filter_by(reference_type = WalletReferenceType._VALUES_TO_NAMES.get(reference_type)).filter_by(amount = -amount).order_by(UserWalletHistory.id.desc()).first()
|
6062 |
previous_debit_history = UserWalletHistory.query.filter_by(reference = reference).filter_by(reference_type = WalletReferenceType._VALUES_TO_NAMES.get(reference_type)).filter_by(amount = -amount).order_by(UserWalletHistory.id.desc()).first()
|
| 6063 |
if history is None:
|
6063 |
if previous_debit_history is None:
|
| 6064 |
print 'No amount was debited from wallet for recharge Id : ' + str(reference)
|
6064 |
print 'No amount was debited from wallet for recharge Id : ' + str(reference)
|
| 6065 |
return
|
6065 |
return
|
| 6066 |
|
6066 |
|
| 6067 |
elif reference_type==WalletReferenceType.PURCHASE:
|
6067 |
elif reference_type==WalletReferenceType.PURCHASE:
|
| 6068 |
history = UserWalletHistory.query.filter_by(reference = reference).filter_by(reference_type = WalletReferenceType._VALUES_TO_NAMES.get(reference_type)).filter_by(amount = -amount).order_by(UserWalletHistory.id.desc()).first()
|
6068 |
previous_debit_history = UserWalletHistory.query.filter_by(reference = reference).filter_by(reference_type = WalletReferenceType._VALUES_TO_NAMES.get(reference_type)).filter_by(amount = -amount).order_by(UserWalletHistory.id.desc()).first()
|
| 6069 |
if history is None:
|
6069 |
if previous_debit_history is None:
|
| 6070 |
print 'No amount was debited from wallet for purchase : ' + str(reference)
|
6070 |
print 'No amount was debited from wallet for purchase : ' + str(reference)
|
| 6071 |
return
|
6071 |
return
|
| 6072 |
|
6072 |
|
| 6073 |
else:
|
6073 |
else:
|
| 6074 |
print "Reference is not valid"
|
6074 |
print "Reference is not valid"
|
| 6075 |
return
|
6075 |
return
|
| 6076 |
|
6076 |
|
| 6077 |
|
6077 |
|
| 6078 |
wallet = get_user_wallet(userId)
|
6078 |
wallet = get_user_wallet(userId)
|
| 6079 |
wallet.amount = wallet.amount + amount
|
6079 |
wallet.amount = wallet.amount + amount
|
| 6080 |
wallet.refundable_amount = wallet.refundable_amount -history.refundable_amount
|
6080 |
wallet.refundable_amount = wallet.refundable_amount -previous_debit_history.refundable_amount
|
| 6081 |
|
6081 |
|
| 6082 |
history = UserWalletHistory()
|
6082 |
history = UserWalletHistory()
|
| 6083 |
history.amount = amount
|
6083 |
history.amount = amount
|
| 6084 |
history.refundable_amount = -history.refundable_amount
|
6084 |
history.refundable_amount = -previous_debit_history.refundable_amount
|
| 6085 |
history.reference = reference
|
6085 |
history.reference = reference
|
| 6086 |
history.reference_type = WalletReferenceType._VALUES_TO_NAMES.get(reference_type)
|
6086 |
history.reference_type = WalletReferenceType._VALUES_TO_NAMES.get(reference_type)
|
| 6087 |
history.wallet = wallet
|
6087 |
history.wallet = wallet
|
| 6088 |
history.timestamp = datetime.datetime.now()
|
6088 |
history.timestamp = datetime.datetime.now()
|
| 6089 |
session.commit()
|
6089 |
session.commit()
|