Reworked the fee calculations structure
This commit was merged in pull request #19.
This commit is contained in:
+13
-10
@@ -1,6 +1,7 @@
|
||||
from datetime import datetime, timezone, timedelta
|
||||
from app.extensions import db
|
||||
from sqlalchemy.orm import relationship
|
||||
from app.utils.logger import logger
|
||||
|
||||
|
||||
class LoanCharge(db.Model):
|
||||
@@ -35,8 +36,8 @@ class LoanCharge(db.Model):
|
||||
charges (list): A list of dictionaries with keys:
|
||||
code (str), amount (float), percent (float), description (str), due (int)
|
||||
"""
|
||||
if not charges or not isinstance(charges, list):
|
||||
raise ValueError("Charges must be a non-empty list of dictionaries")
|
||||
# if not charges or not isinstance(charges, list):
|
||||
# raise ValueError("Charges must be a non-empty list of dictionaries")
|
||||
|
||||
if loan_id is None:
|
||||
raise ValueError("loan_id cannot be None")
|
||||
@@ -44,21 +45,23 @@ class LoanCharge(db.Model):
|
||||
loan_charges = []
|
||||
now = datetime.now(timezone.utc)
|
||||
|
||||
for charge in charges:
|
||||
due_days = getattr(charge, "due", 0)
|
||||
amount = getattr(charge, "amount", 0.0)
|
||||
percent = getattr(charge, "percent", 0.0)
|
||||
|
||||
if amount == 0.0:
|
||||
amount = (percent / 100.0) * referenced_amount
|
||||
subset_keys = ['interest', 'management', 'insurance', 'vat']
|
||||
for item in subset_keys:
|
||||
charge = charges[item]
|
||||
due_days = charge['due_days'] # getattr(charge, "due_days", 0)
|
||||
amount = charge['fee'] # getattr(charge, "fee", 0.0)
|
||||
percent = charge['rate'] # getattr(charge, "rate", 0.0)
|
||||
code = charge['code'] # getattr(charge, "code","")
|
||||
description = charge['description'] # getattr(charge, "description", "")
|
||||
|
||||
charge_obj = cls(
|
||||
loan_id = loan_id,
|
||||
transaction_id = transaction_id,
|
||||
code = getattr(charge, "code"),
|
||||
code = code,
|
||||
amount = round(amount, 2),
|
||||
percent = percent,
|
||||
description = getattr(charge, "description", ""),
|
||||
description = description,
|
||||
due = due_days,
|
||||
due_date = now + timedelta(days=due_days)
|
||||
)
|
||||
|
||||
+5
-1
@@ -75,7 +75,11 @@ class Offer(db.Model):
|
||||
"productId": self.product_id,
|
||||
"minAmount": self.min_amount,
|
||||
"maxAmount": self.max_amount,
|
||||
"tenor": self.tenor
|
||||
"tenor": self.tenor,
|
||||
"interest_rate": self.interest_rate,
|
||||
"management_rate": self.management_rate,
|
||||
"insurance_rate": self.insurance_rate,
|
||||
"vat_rate": self.vat_rate
|
||||
}
|
||||
|
||||
def __repr__(self):
|
||||
|
||||
Reference in New Issue
Block a user