added repayment data to db
This commit was merged in pull request #22.
This commit is contained in:
@@ -4,5 +4,6 @@ from .loan import Loan
|
||||
from .loan_charge import LoanCharge
|
||||
from .customer import Customer
|
||||
from .account import Account
|
||||
from .repayments_data import RepaymentsData
|
||||
|
||||
__all__ = ['Transaction', 'Repayment', 'Loan', 'LoanCharge', 'Customer', 'Account']
|
||||
__all__ = ['Transaction', 'Repayment', 'Loan', 'LoanCharge', 'Customer', 'Account', 'RepaymentsData']
|
||||
@@ -0,0 +1,44 @@
|
||||
from datetime import datetime, timezone
|
||||
from app.extensions import db
|
||||
from app.utils.logger import logger
|
||||
|
||||
class RepaymentsData(db.Model):
|
||||
__tablename__ = 'repayments_data'
|
||||
|
||||
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
|
||||
transaction_id = db.Column(db.String(50), nullable=False)
|
||||
added_date = db.Column(db.DateTime(timezone=True), default=datetime.now(timezone.utc), nullable=False)
|
||||
response_code = db.Column(db.String(10), nullable=True)
|
||||
response_descr = db.Column(db.String(255), nullable=True)
|
||||
|
||||
def to_dict(self):
|
||||
return {
|
||||
"id": self.id,
|
||||
"transaction_id": self.transaction_id,
|
||||
"added_date": self.added_date.isoformat() if self.added_date else None,
|
||||
"response_code": self.response_code,
|
||||
"response_descr": self.response_descr,
|
||||
}
|
||||
|
||||
|
||||
def __repr__(self):
|
||||
return f"<RepaymentsData id={self.id}, transaction_id={self.transaction_id}>"
|
||||
|
||||
@classmethod
|
||||
def add_repayment_data(cls, data):
|
||||
"""
|
||||
Add a new repayment data entry.
|
||||
"""
|
||||
try:
|
||||
new_data = cls(
|
||||
transaction_id=data.get('transactionId'),
|
||||
response_code=data.get('responseCode'),
|
||||
response_descr=data.get('responseMessage')
|
||||
)
|
||||
db.session.add(new_data)
|
||||
db.session.commit()
|
||||
logger.info(f"data has been commited ")
|
||||
return new_data
|
||||
except Exception as e:
|
||||
db.session.rollback()
|
||||
raise Exception(f"Error adding repayment data: {str(e)}")
|
||||
Reference in New Issue
Block a user