debugging

This commit was merged in pull request #34.
This commit is contained in:
Chinenye Nmoh
2025-06-26 18:26:57 +01:00
parent 79109af695
commit 1bf4d61554
5 changed files with 144 additions and 90 deletions
+17 -8
View File
@@ -42,9 +42,13 @@ class RepaymentsData(db.Model):
Add a new repayment data entry.
"""
try:
repaymentAmount = data.get('repaymentAmount', 0.0)
amountCollected = data.get('amountCollected',0.0)
accountBalance = repaymentAmount - amountCollected
repayment_amount = float(data.get('repaymentAmount', 0.0))
amount_collected = float(data.get('amountCollected', 0.0))
if amount_collected < 0 or repayment_amount < 0:
raise ValueError("Amounts cannot be negative.")
account_balance = round(repayment_amount - amount_collected, 2)
new_data = cls(
transaction_id=data.get('transactionId'),
@@ -53,14 +57,19 @@ class RepaymentsData(db.Model):
fbn_transaction_id=data.get('fbnTransactionId'),
account_id=data.get('accountId'),
customer_id=data.get('customerId'),
amount_collected=amountCollected,
repayment_amount=repaymentAmount,
balance=round(float(accountBalance), 2)
amount_collected=amount_collected,
repayment_amount=repayment_amount,
balance=account_balance,
)
db.session.add(new_data)
db.session.commit()
logger.info(f"data has been commited ")
logger.info("Repayment data committed successfully")
return new_data
except Exception as e:
db.session.rollback()
raise Exception(f"Error adding repayment data: {str(e)}")
logger.error(f"Error adding repayment data: {e}")
raise Exception(f"Error adding repayment data: {str(e)}")