[add]: Update loan status after repayment
This commit was merged in pull request #6.
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
from flask import request, jsonify
|
||||
from marshmallow import ValidationError
|
||||
from app.api.enums.loan_status import LoanStatus
|
||||
from app.models import Repayment
|
||||
from app.models.loan import Loan
|
||||
from app.utils.logger import logger
|
||||
from app.api.schemas.repayment import RepaymentSchema
|
||||
from app.api.services.base_service import BaseService
|
||||
@@ -28,6 +30,7 @@ class RepaymentService(BaseService):
|
||||
account = customer.accounts[0]
|
||||
validated_data['accountId'] = account.id
|
||||
request_id = validated_data.get('requestId')
|
||||
loan_id = validated_data.get('debtId')
|
||||
|
||||
|
||||
if (RepaymentService.validate_account_ownership(account_id = account.id, customer_id = customer_id)):
|
||||
@@ -35,7 +38,7 @@ class RepaymentService(BaseService):
|
||||
# Save the repayment details
|
||||
repayment = Repayment.create_repayment(
|
||||
customer_id = customer_id,
|
||||
loan_id = validated_data.get('debtId'),
|
||||
loan_id = loan_id,
|
||||
product_id = validated_data.get('productId')
|
||||
|
||||
)
|
||||
@@ -46,6 +49,9 @@ class RepaymentService(BaseService):
|
||||
"message": "Failed to save repayment details."
|
||||
}), 400
|
||||
|
||||
#Update Loan status
|
||||
Loan.update_status(loan_id = loan_id, status = LoanStatus.REPAID)
|
||||
|
||||
transaction = RepaymentService.log_transaction(validated_data = validated_data)
|
||||
|
||||
if not transaction:
|
||||
|
||||
Reference in New Issue
Block a user