update
This commit was merged in pull request #1.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
from .customer import Customer
|
||||
from .account import Account
|
||||
from .loan import Loan
|
||||
from .transaction import Transaction
|
||||
|
||||
__all__ = ['Customer', 'Loan', 'Transaction']
|
||||
__all__ = ['Customer', 'Account', 'Loan', 'Transaction']
|
||||
@@ -3,7 +3,6 @@ from app.extensions import db
|
||||
from sqlalchemy.exc import IntegrityError
|
||||
from sqlalchemy import and_, or_, not_
|
||||
|
||||
|
||||
class Transaction(db.Model):
|
||||
__tablename__ = 'transactions'
|
||||
id = db.Column(
|
||||
@@ -11,9 +10,9 @@ class Transaction(db.Model):
|
||||
primary_key=True,
|
||||
autoincrement=True,
|
||||
)
|
||||
# id = db.Column(db.Int, primary_key=True)
|
||||
transaction_id = db.Column(db.String(50), nullable=False)
|
||||
account_id = db.Column(db.String(50), nullable=False)
|
||||
account_id = db.Column(db.String(50), nullable=True)
|
||||
customer_id = db.Column(db.String(50), nullable=True)
|
||||
type = db.Column(db.String(50), nullable=False)
|
||||
channel = db.Column(db.String(50), nullable=False)
|
||||
created_at = db.Column(db.DateTime, default=datetime.now(timezone.utc))
|
||||
@@ -23,26 +22,25 @@ class Transaction(db.Model):
|
||||
return f'<Transaction {self.id}>'
|
||||
|
||||
@classmethod
|
||||
def create_transaction(cls, transaction_id, account_id, type, channel):
|
||||
def create_transaction(cls, transaction_id, account_id, customer_id, type, channel):
|
||||
|
||||
# if cls.query.filter_by(transaction_id=transaction_id).first():
|
||||
# raise ValueError("Duplicate Transaction")
|
||||
|
||||
if cls.query.filter(and_(cls.transaction_id == transaction_id, cls.type == type)).first():
|
||||
if cls.query.filter( and_( cls.transaction_id ==transaction_id, cls.type==type) ).first():
|
||||
raise ValueError("Duplicate Transaction")
|
||||
|
||||
transaction = cls(
|
||||
transaction_id=transaction_id,
|
||||
account_id=account_id,
|
||||
type=type,
|
||||
channel=channel
|
||||
transaction_id = transaction_id,
|
||||
customer_id = customer_id,
|
||||
account_id = account_id,
|
||||
type = type,
|
||||
channel = channel
|
||||
)
|
||||
|
||||
try:
|
||||
db.session.add(transaction)
|
||||
db.session.commit()
|
||||
except IntegrityError as err:
|
||||
db.session.rollback()
|
||||
raise ValueError(f"Database integrity error: {err}")
|
||||
|
||||
return transaction
|
||||
|
||||
Reference in New Issue
Block a user