Merge branch 'add_dafaults_to_provide_loan_response' of DigiFi/digifi-BankToProductCore into master
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
from gettext import install
|
||||||
from flask import request, jsonify
|
from flask import request, jsonify
|
||||||
from marshmallow import ValidationError
|
from marshmallow import ValidationError
|
||||||
from app.api.integrations.kafka import KafkaIntegration
|
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):
|
def get_charge_schedule_items(cls, loan_charges, offer, loan_ref, amount, schedules):
|
||||||
now = datetime.now(timezone.utc)
|
now = datetime.now(timezone.utc)
|
||||||
due_date = now + timedelta(days=offer.tenor)
|
due_date = now + timedelta(days=offer.tenor)
|
||||||
|
id_counter = 1
|
||||||
|
|
||||||
charge_schedule_items = []
|
charge_schedule_items = []
|
||||||
|
|
||||||
charge_schedule_items.append({
|
charge_schedule_items.append({
|
||||||
"id": 1,
|
"id": id_counter,
|
||||||
"dueDate": due_date.isoformat(),
|
"dueDate": due_date.isoformat(),
|
||||||
"amountDue": amount,
|
"amountDue": amount,
|
||||||
"componentName": "PRINCIPAL",
|
"componentName": "PRINCIPAL",
|
||||||
"startDate": now.isoformat(),
|
"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 = {
|
item = {
|
||||||
"id": idx,
|
"id": id_counter,
|
||||||
"dueDate": charge.due_date.isoformat(),
|
"dueDate": charge.due_date.isoformat(),
|
||||||
"amountDue": float(charge.amount),
|
"amountDue": float(charge.amount),
|
||||||
"componentName": charge.code.upper(), # e.g. INTEREST, MGMT_FEE, VAT_FEE
|
"componentName": charge.code.upper(), # e.g. INTEREST, MGMT_FEE, VAT_FEE
|
||||||
"startDate": charge.created_at.isoformat(),
|
"startDate": charge.created_at.isoformat(),
|
||||||
}
|
}
|
||||||
|
|
||||||
if charge.code.upper() == "INTEREST":
|
if charge.code.upper() == "VAT":
|
||||||
item["loanRef"] = loan_ref
|
item["loanRef"] = loan_ref
|
||||||
|
|
||||||
charge_schedule_items.append(item)
|
charge_schedule_items.append(item)
|
||||||
|
id_counter += 1
|
||||||
|
|
||||||
|
|
||||||
for idx, schedule in enumerate(schedules, start=len(charge_schedule_items) + 1):
|
num_schedules = len(schedules)
|
||||||
item = {
|
if num_schedules > 0:
|
||||||
"id": idx,
|
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(),
|
"dueDate": schedule.due_date.isoformat(),
|
||||||
"amountDue": float(schedule.installment_amount),
|
"amountDue": round(principal_per_schedule, 2),
|
||||||
"componentName": "DEFAULT",
|
"componentName": "DEFAULT",
|
||||||
"startDate": schedule.created_at.isoformat(),
|
"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
|
"loanRef": loan_ref
|
||||||
}
|
}
|
||||||
charge_schedule_items.append(item)
|
|
||||||
|
charge_schedule_items.append(interest)
|
||||||
|
id_counter += 1
|
||||||
|
|
||||||
return charge_schedule_items
|
return charge_schedule_items
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user