Handle duplicate repayment attempts
This commit is contained in:
@@ -57,7 +57,7 @@ class RepaymentService(BaseService):
|
|||||||
return ResponseHelper.error(result_description="Failed to save repayment details.")
|
return ResponseHelper.error(result_description="Failed to save repayment details.")
|
||||||
|
|
||||||
#Update Loan status
|
#Update Loan status
|
||||||
Loan.update_status(loan_id = loan_id, status = LoanStatus.START_REPAY) # repay started bu user
|
Loan.update_status(loan_id = loan_id, status = LoanStatus.START_REPAY) # repay started by user
|
||||||
transaction = RepaymentService.log_transaction(validated_data = validated_data)
|
transaction = RepaymentService.log_transaction(validated_data = validated_data)
|
||||||
|
|
||||||
if not transaction:
|
if not transaction:
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ from app.models import account
|
|||||||
from sqlalchemy.exc import IntegrityError
|
from sqlalchemy.exc import IntegrityError
|
||||||
from sqlalchemy import and_, or_, not_
|
from sqlalchemy import and_, or_, not_
|
||||||
from sqlalchemy.sql import func
|
from sqlalchemy.sql import func
|
||||||
|
from app.api.enums import TransactionType
|
||||||
|
|
||||||
|
|
||||||
class Transaction(db.Model):
|
class Transaction(db.Model):
|
||||||
__tablename__ = 'transactions'
|
__tablename__ = 'transactions'
|
||||||
@@ -30,17 +32,21 @@ class Transaction(db.Model):
|
|||||||
# if cls.query.filter_by(transaction_id=transaction_id).first():
|
# if cls.query.filter_by(transaction_id=transaction_id).first():
|
||||||
# raise ValueError("Duplicate Transaction")
|
# 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")
|
if type == TransactionType.REPAYMENT:
|
||||||
|
logger.info('Repayment transaction already exists :::: But we like to continue.')
|
||||||
|
now = datetime.now()
|
||||||
|
type = TransactionType.REPAYMENT + '.'+ now.strftime("%Y%m%d%H%M%S")
|
||||||
|
logger.info('Modify Type :::: {0}'.format(type))
|
||||||
|
else:
|
||||||
|
raise ValueError("Duplicate Transaction")
|
||||||
|
|
||||||
transaction = cls(
|
transaction = cls(
|
||||||
transaction_id = transaction_id,
|
transaction_id=transaction_id,
|
||||||
customer_id = customer_id,
|
customer_id=customer_id,
|
||||||
account_id = account_id,
|
account_id=account_id,
|
||||||
type = type,
|
type=type,
|
||||||
channel = channel,
|
channel=channel,
|
||||||
created_at=datetime.now(timezone.utc),
|
created_at=datetime.now(timezone.utc),
|
||||||
updated_at=datetime.now(timezone.utc)
|
updated_at=datetime.now(timezone.utc)
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user