[fix]: Loan fees
This commit is contained in:
@@ -79,41 +79,51 @@ class BaseService:
|
|||||||
return {"error": "No charges found for the offer"}
|
return {"error": "No charges found for the offer"}
|
||||||
|
|
||||||
loan_charges = offer.charges
|
loan_charges = offer.charges
|
||||||
interest = cls.get_charge_detail(loan_charges, "INTEREST", amount)
|
tenor = offer.tenor // 30 # Convert to months
|
||||||
management = cls.get_charge_detail(loan_charges, "MGTFEE", amount)
|
interest = cls.get_charge_detail(charges = loan_charges, code = "INTEREST", amount = amount)
|
||||||
insurance = cls.get_charge_detail(loan_charges, "INSURANCE", amount)
|
management = cls.get_charge_detail(charges = loan_charges, code = "MGTFEE", amount = amount)
|
||||||
vat = cls.get_charge_detail(loan_charges, "VAT", amount)
|
insurance = cls.get_charge_detail(charges = loan_charges, code = "INSURANCE", amount = amount)
|
||||||
|
vat = cls.get_charge_detail(charges = loan_charges, code = "VAT", amount = amount, management_fee = management["fee"])
|
||||||
|
|
||||||
# Up-front payment: (principal + only those fees due immediately i.e due_days == 0)
|
# Separate fees into upfront and postpaid
|
||||||
upfront_payment = amount + sum(
|
upfront_fees = [
|
||||||
amount * charge.percent / 100
|
fee["fee"]
|
||||||
for charge in loan_charges
|
for fee in [interest, management, insurance, vat]
|
||||||
if charge.due == 0
|
if fee["due_days"] == 0
|
||||||
)
|
]
|
||||||
|
|
||||||
# Total amount: (principal + all fees)
|
postpaid_fees = [
|
||||||
total_amount = amount + sum(
|
fee["fee"]
|
||||||
amount * charge.percent / 100
|
for fee in [interest, management, insurance, vat]
|
||||||
for charge in loan_charges
|
if fee["due_days"] != 0
|
||||||
)
|
]
|
||||||
|
|
||||||
|
# Up-front payment: (only those fees due immediately i.e due_days == 0)
|
||||||
|
upfront_payment = sum(upfront_fees)
|
||||||
|
|
||||||
|
# Repayment amount: (principal + only those fees not due immediately i.e due_days != 0)
|
||||||
|
repayment_amount = amount + sum(postpaid_fees) * tenor
|
||||||
|
|
||||||
|
# Total amount: (upfront_payment + repayment_amount)
|
||||||
|
total_amount = upfront_payment + repayment_amount
|
||||||
|
|
||||||
# Calculate the installment amount
|
# Calculate the installment amount
|
||||||
tenor = offer.tenor
|
installment_amount = repayment_amount / tenor
|
||||||
installment_amount = total_amount / tenor
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"interest": interest,
|
"interest": interest,
|
||||||
"management": management,
|
"management": management,
|
||||||
"insurance": insurance,
|
"insurance": insurance,
|
||||||
"vat": vat,
|
"vat": vat,
|
||||||
"upfront_payment": upfront_payment,
|
"upfront_payment": round(upfront_payment, 2),
|
||||||
"total_amount": total_amount,
|
"repayment_amount": round(repayment_amount, 2),
|
||||||
"installment_amount": installment_amount
|
"installment_amount": round(installment_amount, 2),
|
||||||
|
"total_amount": round(total_amount, 2)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_charge_detail(cls, charges, code, amount):
|
def get_charge_detail(cls, charges, code, amount, management_fee=None):
|
||||||
"""
|
"""
|
||||||
Get details for a specific charge code from a list of loan charges.
|
Get details for a specific charge code from a list of loan charges.
|
||||||
|
|
||||||
@@ -123,10 +133,16 @@ class BaseService:
|
|||||||
|
|
||||||
for charge in charges:
|
for charge in charges:
|
||||||
if charge.code == code:
|
if charge.code == code:
|
||||||
|
fee = (
|
||||||
|
management_fee * charge.percent / 100
|
||||||
|
if code == "VAT" and management_fee is not None
|
||||||
|
else amount * charge.percent / 100
|
||||||
|
)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"rate": charge.percent,
|
"rate": charge.percent,
|
||||||
"fee": amount * charge.percent / 100,
|
"fee": fee,
|
||||||
"due_days": charge.due,
|
"due_days": charge.due
|
||||||
}
|
}
|
||||||
|
|
||||||
return {"rate": 0, "fee": 0, "due_days": 0}
|
return {"rate": 0, "fee": 0, "due_days": 0}
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ class ProvideLoanService(BaseService):
|
|||||||
|
|
||||||
charges = ProvideLoanService.calculate_charges(offer, amount)
|
charges = ProvideLoanService.calculate_charges(offer, amount)
|
||||||
upfront_fee = charges["upfront_payment"]
|
upfront_fee = charges["upfront_payment"]
|
||||||
repayment_amount = charges["total_amount"]
|
repayment_amount = charges["repayment_amount"]
|
||||||
installment_amount = charges["installment_amount"]
|
installment_amount = charges["installment_amount"]
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -37,5 +37,5 @@ confluent-kafka==1.9.2
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
python-dateutil>=2.8.0
|
python-dateutil
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user