diff --git a/app/routes/autocall.py b/app/routes/autocall.py index 4abdaf3..5a0f47b 100644 --- a/app/routes/autocall.py +++ b/app/routes/autocall.py @@ -125,12 +125,18 @@ def direct_loan(): loan = LoanService.get_loan_by_transaction_id(transaction_id=transaction_id) if not loan: - logger.warning(f"Loan with transaction id {transaction_id} does not exist") - return jsonify({ - "status": "error", - "message": f"Loan with transaction id {transaction_id} does not exist" - }), 400 + first_error = f"Loan with transaction id {transaction_id} does not exist" + logger.warning(first_error) + loan = LoanService.get_latest_loan_without_disburse_date() + if not loan: + logger.info(f"No loan found without disbursement date") + return jsonify({ + "status": "error", + "first_error": first_error, + "message": f"No loan found without disbursement date" + }), 400 + # Tried 2 method to get the loan record at this point loan_data = loan.to_dict() # Prevent double disbursement