overdue loans
This commit was merged in pull request #45.
This commit is contained in:
@@ -308,48 +308,8 @@ class SimbrellaClient:
|
||||
amount_collected = Decimal(str(result.get('amountCollected', 0))).quantize(Decimal('0.01'), rounding=ROUND_HALF_UP)
|
||||
logger.info(f"Amount collected: {amount_collected}")
|
||||
|
||||
if loan.balance is None or loan.balance <= 0:
|
||||
logger.warning(f"Loan ID {loan.id} has no balance. Skipping loan update.")
|
||||
updated_loan = loan.to_dict()
|
||||
#return ResponseHelper.error("Loan has no balance. Skipping.")
|
||||
else:
|
||||
|
||||
try:
|
||||
logger.info(f"Updating loan balance for loan ID {loan_data['debtId']} with amount collected: {amount_collected}")
|
||||
updated_loan = LoanService.update_loan_balance(int(loan_data['debtId']), amount_collected)
|
||||
logger.info(f"Updated loan: {updated_loan}")
|
||||
except Exception as ex:
|
||||
db.session.rollback()
|
||||
logger.error(f"Error updating loan balance for loan ID {loan.id}: {ex}")
|
||||
return ResponseHelper.error("Error updating loan balance")
|
||||
|
||||
try:
|
||||
updated_balance = Decimal(str(updated_loan['balance'])).quantize(Decimal('0.01'))
|
||||
logger.info(f"Updated balance: {updated_balance}")
|
||||
|
||||
if updated_balance <= Decimal('0.00'):
|
||||
logger.info('Loan fully repaid')
|
||||
repaid = LoanService.update_status(updated_loan['debtId'], LoanStatus.REPAID)
|
||||
logger.info(f'Updated loan with repaid status: {repaid}')
|
||||
updated_loan = repaid
|
||||
else:
|
||||
logger.info('Loan partially repaid')
|
||||
partial = LoanService.update_status(updated_loan['debtId'], LoanStatus.ACTIVE_PARTIAL)
|
||||
logger.info(f'Updated loan with partial status: {partial}')
|
||||
updated_loan = partial
|
||||
|
||||
except Exception as e:
|
||||
db.session.rollback()
|
||||
logger.error(f"Error while updating loan status for debtId {updated_loan['debtId']}: {e}")
|
||||
# lets update the loan repayment schedule when full payment has been made
|
||||
# get the repayment schedule by loan_id
|
||||
logger.info(f"Updated loan status: {updated_loan.get('status')}")
|
||||
LoanRepaymentScheduleService.handle_schedule_updates(
|
||||
updated_loan=updated_loan,
|
||||
data=data,
|
||||
amount_collected=amount_collected,
|
||||
message=response_message,
|
||||
loan_data=loan_data
|
||||
updated_loan = LoanService._update_loan_after_collection(
|
||||
loan, loan_data, updated_loan, amount_collected, data, response_message=response_message
|
||||
)
|
||||
return ResponseHelper.success(result, "Successful")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user