Merge branch 'loan_charges_on_loans' of DigiFi/digifi-BankToProductCore into master
This commit is contained in:
@@ -90,7 +90,7 @@ class ProvideLoanService(BaseService):
|
||||
]
|
||||
loan_id = loan.id
|
||||
|
||||
loan_charges = LoanCharge.create_charges_for_loan(loan_id = loan_id, charges = charges)
|
||||
loan_charges = LoanCharge.create_charges_for_loan(loan_id = loan_id, transaction_id = transaction_id, referenced_amount = 800, charges = charges)
|
||||
|
||||
|
||||
# logger.error(f"********* We need to develop the fee array here")
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from datetime import datetime, timezone
|
||||
from datetime import datetime, timezone, timedelta
|
||||
from app.extensions import db
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
@@ -8,11 +8,13 @@ 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)
|
||||
description = db.Column(db.Text, nullable=True)
|
||||
due = db.Column(db.Integer, nullable=False)
|
||||
due_date = db.Column(db.DateTime, nullable=True)
|
||||
created_at = db.Column(db.DateTime, default=datetime.now(timezone.utc))
|
||||
updated_at = db.Column(db.DateTime, default=datetime.now(timezone.utc), onupdate=datetime.now(timezone.utc))
|
||||
|
||||
@@ -24,7 +26,7 @@ class LoanCharge(db.Model):
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def create_charges_for_loan(cls, loan_id, charges):
|
||||
def create_charges_for_loan(cls, loan_id, transaction_id, charges, referenced_amount = 0.0):
|
||||
"""
|
||||
Create loan charges for a given loan.
|
||||
|
||||
@@ -40,15 +42,27 @@ class LoanCharge(db.Model):
|
||||
raise ValueError("loan_id cannot be None")
|
||||
|
||||
loan_charges = []
|
||||
now = datetime.now(timezone.utc)
|
||||
|
||||
for charge in charges:
|
||||
due_days = charge.get("due", 0)
|
||||
amount = charge.get("amount", 0.0)
|
||||
percent = charge.get("percent", 0.0)
|
||||
|
||||
if amount == 0.0:
|
||||
amount = (percent / 100.0) * referenced_amount
|
||||
|
||||
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)
|
||||
loan_id = loan_id,
|
||||
transaction_id = transaction_id,
|
||||
code = charge.get("code"),
|
||||
amount = amount,
|
||||
percent = percent,
|
||||
description = charge.get("description", ""),
|
||||
due = due_days,
|
||||
due_date = now + timedelta(days=due_days)
|
||||
)
|
||||
|
||||
db.session.add(charge_obj)
|
||||
loan_charges.append(charge_obj)
|
||||
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
"""Migration on Thu Apr 17 10:40:05 UTC 2025
|
||||
|
||||
Revision ID: ec8d97f9b584
|
||||
Revises: 287ecb02d3d7
|
||||
Create Date: 2025-04-17 10:40:34.751272
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = 'ec8d97f9b584'
|
||||
down_revision = '287ecb02d3d7'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
with op.batch_alter_table('loan_charges', schema=None) as batch_op:
|
||||
batch_op.add_column(sa.Column('transaction_id', sa.String(length=50), nullable=True))
|
||||
batch_op.add_column(sa.Column('due_date', sa.DateTime(), nullable=True))
|
||||
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
with op.batch_alter_table('loan_charges', schema=None) as batch_op:
|
||||
batch_op.drop_column('due_date')
|
||||
batch_op.drop_column('transaction_id')
|
||||
|
||||
# ### end Alembic commands ###
|
||||
Reference in New Issue
Block a user