eliminated some hardcoded values
This commit is contained in:
@@ -1,4 +1,8 @@
|
||||
from .transactions import Transaction
|
||||
from .repayment import Repayment
|
||||
from .loan import Loan
|
||||
from .loan_charge import LoanCharge
|
||||
from .customer import Customer
|
||||
from .account import Account
|
||||
|
||||
__all__ = ['Transaction', 'Repayment']
|
||||
__all__ = ['Transaction', 'Repayment', 'Loan', 'LoanCharge', 'Customer', 'Account']
|
||||
@@ -0,0 +1,25 @@
|
||||
from datetime import datetime, timezone
|
||||
from sqlalchemy.orm import relationship
|
||||
from app.extensions import db
|
||||
|
||||
|
||||
class Account(db.Model):
|
||||
__tablename__ = 'accounts'
|
||||
|
||||
id = db.Column(db.String(50), primary_key=True)
|
||||
customer_id = db.Column(db.String(50), nullable=False)
|
||||
account_type = db.Column(db.String(50))
|
||||
status = db.Column(db.String(20), default='active')
|
||||
lien_amount = db.Column(db.Float, default=0.0)
|
||||
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))
|
||||
|
||||
customer = relationship(
|
||||
"Customer",
|
||||
primaryjoin="Customer.id == Account.customer_id",
|
||||
foreign_keys=[customer_id],
|
||||
back_populates="accounts",
|
||||
)
|
||||
|
||||
def __repr__(self):
|
||||
return f'<Account {self.id}>'
|
||||
@@ -0,0 +1,41 @@
|
||||
from datetime import datetime, timezone
|
||||
from sqlalchemy.orm import relationship
|
||||
from app.extensions import db
|
||||
|
||||
|
||||
class Customer(db.Model):
|
||||
__tablename__ = 'customers'
|
||||
|
||||
id = db.Column(db.String(50), primary_key=True)
|
||||
msisdn = db.Column(db.String(20), unique=True, nullable=False)
|
||||
country_code = db.Column(db.String(3), nullable=False)
|
||||
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))
|
||||
|
||||
accounts = relationship(
|
||||
"Account",
|
||||
primaryjoin="Customer.id == Account.customer_id",
|
||||
foreign_keys="Account.customer_id",
|
||||
back_populates="customer",
|
||||
)
|
||||
|
||||
loans = relationship(
|
||||
"Loan",
|
||||
primaryjoin="Customer.id == Loan.customer_id",
|
||||
foreign_keys="Loan.customer_id",
|
||||
back_populates="customer",
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def get_customer(cls, customer_id):
|
||||
"""
|
||||
Get customer by ID.
|
||||
"""
|
||||
customer = cls.query.filter_by(id=customer_id).first()
|
||||
|
||||
if not customer:
|
||||
raise ValueError(f"Customer does not exist")
|
||||
return customer
|
||||
|
||||
def __repr__(self):
|
||||
return f'<Customer {self.id}>'
|
||||
+6
-1
@@ -54,6 +54,11 @@ class Loan(db.Model):
|
||||
'continuousFee': self.continuous_fee,
|
||||
'collectionType': self.collection_type,
|
||||
'status': self.status,
|
||||
'productId': self.product_id,
|
||||
'dueDate': self.due_date.isoformat() if self.due_date else None,
|
||||
'loanDate': self.created_at.isoformat if self.created_at else None
|
||||
}
|
||||
}
|
||||
|
||||
@classmethod
|
||||
def get_loan_by_transaction_id(cls, transaction_id):
|
||||
return cls.query.filter_by(transaction_id=transaction_id).first()
|
||||
@@ -1,4 +1,6 @@
|
||||
from datetime import datetime, timezone, timedelta
|
||||
from os.path import devnull
|
||||
|
||||
from app.extensions import db
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
@@ -40,4 +42,8 @@ class LoanCharge(db.Model):
|
||||
'percent': self.percent,
|
||||
'description': self.description,
|
||||
'due': self.due
|
||||
}
|
||||
}
|
||||
|
||||
@classmethod
|
||||
def get_loan_charge_by_debt_id(cls, debt_id):
|
||||
return cls.query.filter_by(loan_id=debt_id)
|
||||
Reference in New Issue
Block a user