Repayment updates
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
from app.extensions import db
|
||||
from datetime import datetime, timezone
|
||||
from app.utils.logger import logger
|
||||
from app.enums.loan_status import LoanStatus
|
||||
|
||||
class Repayment(db.Model):
|
||||
__tablename__ = "repayments"
|
||||
@@ -47,6 +48,28 @@ class Repayment(db.Model):
|
||||
'VerifyDate': self.verify_date.isoformat() if self.verify_date else None,
|
||||
}
|
||||
|
||||
@classmethod
|
||||
def create_repayment(cls, repayment_data):
|
||||
|
||||
if loan.status not in [LoanStatus.ACTIVE, LoanStatus.START_REPAY]:
|
||||
raise ValueError(f"Repayment cannot be processed. Loan status: ({loan.status})")
|
||||
|
||||
repayment = cls(
|
||||
customer_id=repayment_data.customerId,
|
||||
loan_id=repayment_data.loanId,
|
||||
product_id=repayment_data.productId,
|
||||
transaction_id=repayment_data.transactionId,
|
||||
created_at=datetime.now(timezone.utc),
|
||||
updated_at=datetime.now(timezone.utc),
|
||||
initiated_by= repayment_data.initiated_by
|
||||
)
|
||||
|
||||
try:
|
||||
db.session.add(repayment)
|
||||
except IntegrityError as err:
|
||||
logger.error(f"Database integrity error: {err}")
|
||||
return repayment
|
||||
|
||||
|
||||
@classmethod
|
||||
def add_repayment(cls, data: dict):
|
||||
|
||||
Reference in New Issue
Block a user