forked from DigiFi/digifi-BankToProductCore
[update]: added interest to response and fixed defaults amounts due
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
from gettext import install
|
||||
from flask import request, jsonify
|
||||
from marshmallow import ValidationError
|
||||
from app.api.integrations.kafka import KafkaIntegration
|
||||
@@ -218,42 +219,75 @@ class ProvideLoanService(BaseService):
|
||||
def get_charge_schedule_items(cls, loan_charges, offer, loan_ref, amount, schedules):
|
||||
now = datetime.now(timezone.utc)
|
||||
due_date = now + timedelta(days=offer.tenor)
|
||||
id_counter = 1
|
||||
|
||||
charge_schedule_items = []
|
||||
|
||||
charge_schedule_items.append({
|
||||
"id": 1,
|
||||
"id": id_counter,
|
||||
"dueDate": due_date.isoformat(),
|
||||
"amountDue": amount,
|
||||
"componentName": "PRINCIPAL",
|
||||
"startDate": now.isoformat(),
|
||||
})
|
||||
|
||||
for idx, charge in enumerate(loan_charges, start=len(charge_schedule_items) + 1):
|
||||
|
||||
interest_amount = 0.0
|
||||
|
||||
for charge in loan_charges:
|
||||
|
||||
code = charge.code.upper()
|
||||
|
||||
if code == "INTEREST":
|
||||
interest_amount = float(charge.amount)
|
||||
continue
|
||||
|
||||
|
||||
item = {
|
||||
"id": idx,
|
||||
"id": id_counter,
|
||||
"dueDate": charge.due_date.isoformat(),
|
||||
"amountDue": float(charge.amount),
|
||||
"componentName": charge.code.upper(), # e.g. INTEREST, MGMT_FEE, VAT_FEE
|
||||
"startDate": charge.created_at.isoformat(),
|
||||
}
|
||||
|
||||
if charge.code.upper() == "INTEREST":
|
||||
if charge.code.upper() == "VAT":
|
||||
item["loanRef"] = loan_ref
|
||||
|
||||
charge_schedule_items.append(item)
|
||||
id_counter += 1
|
||||
|
||||
|
||||
for idx, schedule in enumerate(schedules, start=len(charge_schedule_items) + 1):
|
||||
item = {
|
||||
"id": idx,
|
||||
num_schedules = len(schedules)
|
||||
if num_schedules > 0:
|
||||
principal_per_schedule = amount / num_schedules
|
||||
else:
|
||||
principal_per_schedule = 0.0
|
||||
|
||||
|
||||
for schedule in schedules:
|
||||
default = {
|
||||
"id": id_counter,
|
||||
"installmentNo": schedule.installment_number,
|
||||
"dueDate": schedule.due_date.isoformat(),
|
||||
"amountDue": float(schedule.installment_amount),
|
||||
"amountDue": round(principal_per_schedule, 2),
|
||||
"componentName": "DEFAULT",
|
||||
"startDate": schedule.created_at.isoformat(),
|
||||
}
|
||||
|
||||
charge_schedule_items.append(default)
|
||||
id_counter += 1
|
||||
|
||||
interest = {
|
||||
"id": id_counter,
|
||||
"dueDate": schedule.due_date.isoformat(),
|
||||
"amountDue": round(interest_amount, 2),
|
||||
"componentName": "INTEREST",
|
||||
"startDate": schedule.created_at.isoformat(),
|
||||
"loanRef": loan_ref
|
||||
}
|
||||
charge_schedule_items.append(item)
|
||||
|
||||
charge_schedule_items.append(interest)
|
||||
id_counter += 1
|
||||
|
||||
return charge_schedule_items
|
||||
|
||||
|
||||
Reference in New Issue
Block a user