added repayment_schedule
This commit is contained in:
@@ -274,7 +274,11 @@ class SimbrellaClient:
|
||||
"customerId": repayment_data['customerId'],
|
||||
"accountId": loan_data['accountId'],
|
||||
"productId": repayment_data['productId'],
|
||||
"collectAmount": loan_data['balance'] or 0,
|
||||
"collectAmount": (
|
||||
data['overdueLoanScheduleAmount']
|
||||
if data.get('overdueLoanScheduleAmount') is not None
|
||||
else loan_data.get('balance', 0)
|
||||
),
|
||||
"penalCharge": 0,
|
||||
"channel": "USSD",
|
||||
"collectionMethod": collectionMethod,
|
||||
@@ -353,12 +357,45 @@ class SimbrellaClient:
|
||||
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
|
||||
|
||||
try:
|
||||
schedule_to_update = LoanRepaymentScheduleService.get_repayment_schedule_by_id_and_transaction_id(
|
||||
data["overdueLoanScheduleId"], data["transactionId"]
|
||||
)
|
||||
logger.info(f"Schedule to update: {schedule_to_update}")
|
||||
|
||||
if schedule_to_update is None:
|
||||
logger.warning(
|
||||
f"Repayment schedule not found for ID {data['overdueLoanScheduleId']} "
|
||||
f"and transaction ID {loan_data['transactionId']}"
|
||||
)
|
||||
else:
|
||||
# Use DB installment amount as the reference
|
||||
installment_amount = Decimal(str(schedule_to_update.installment_amount)).quantize(Decimal("0.01"))
|
||||
|
||||
if amount_collected >= installment_amount:
|
||||
LoanRepaymentScheduleService.update_repayment_schedule_status(
|
||||
schedule_to_update.id, paid=True)
|
||||
logger.info(
|
||||
f"Installment {data['overdueLoanScheduleId']} fully covered "
|
||||
f"with {amount_collected}, marked as paid"
|
||||
)
|
||||
else:
|
||||
logger.info(
|
||||
f"Installment {data['overdueLoanScheduleId']} not fully covered. "
|
||||
f"Collected={amount_collected}, "
|
||||
f"Installment={installment_amount}"
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to update repayment schedule installment: {e}")
|
||||
|
||||
|
||||
except Exception as e:
|
||||
db.session.rollback()
|
||||
logger.error(f"Error while updating loan status for debtId {updated_loan['debtId']}: {e}")
|
||||
|
||||
Reference in New Issue
Block a user