[add]: loan charges and offers. Fix RACCheck

This commit is contained in:
VivianDee
2025-04-16 21:36:26 +01:00
parent 359621dc9d
commit 93ed8b3d17
12 changed files with 161 additions and 71 deletions
+32 -2
View File
@@ -8,7 +8,6 @@ class LoanCharge(db.Model):
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
loan_id = db.Column(db.Integer, nullable=False)
transaction_id = db.Column(db.String(50), nullable=True)
code = db.Column(db.String(50), nullable=False)
amount = db.Column(db.Float, default=0.0)
percent = db.Column(db.Float, default=0.0)
@@ -24,7 +23,38 @@ class LoanCharge(db.Model):
back_populates="loan_charges",
)
@classmethod
def create_charges_for_loan(cls, loan_id, charges):
"""
Create loan charges for a given loan.
Args:
loan_id (int): ID of the loan to associate charges with.
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 loan_id is None:
raise ValueError("loan_id cannot be None")
loan_charges = []
for charge in charges:
charge_obj = cls(
loan_id=loan_id,
code=charge.get("code"),
amount=charge.get("amount", 0.0),
percent=charge.get("percent", 0.0),
description=charge.get("description", ""),
due=charge.get("due", 0)
)
db.session.add(charge_obj)
loan_charges.append(charge_obj)
return loan_charges
def to_dict(self):
return {