From aba5a021971064fab33d9925402d0687748e00ae Mon Sep 17 00:00:00 2001 From: VivianDee <115420678+VivianDee@users.noreply.github.com> Date: Wed, 16 Apr 2025 13:30:20 +0100 Subject: [PATCH] [update]: Loan Charge model --- app/api/services/provide_loan.py | 8 +++++++- app/models/loan.py | 3 ++- app/models/loan_charge.py | 4 ++-- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/app/api/services/provide_loan.py b/app/api/services/provide_loan.py index 108bbac..74c470c 100644 --- a/app/api/services/provide_loan.py +++ b/app/api/services/provide_loan.py @@ -33,6 +33,11 @@ class ProvideLoanService(BaseService): request_id = validated_data.get('requestId') collection_type = validated_data.get('collectionType') transaction_id = validated_data.get('transactionId') + offer_id = validated_data.get('offerId') + product_id = validated_data.get('productrId') + + + if (ProvideLoanService.validate_account_ownership(account_id = account_id, customer_id = customer_id)): @@ -50,7 +55,8 @@ class ProvideLoanService(BaseService): loan = Loan.create_loan( customer_id = customer_id, account_id = account_id, - offer_id = validated_data.get('offerId'), + offer_id = offer_id, + product_id = product_id, collection_type = collection_type, transaction_id = validated_data.get('transactionId'), initial_loan_amount = validated_data.get('requestedAmount'), diff --git a/app/models/loan.py b/app/models/loan.py index df46f9a..cddec15 100644 --- a/app/models/loan.py +++ b/app/models/loan.py @@ -19,6 +19,7 @@ class Loan(db.Model): transaction_id = db.Column(db.String(50), nullable=True) account_id = db.Column(db.String(50), nullable=False) offer_id = db.Column(db.String(20), nullable=False) + product_id = db.Column(db.String(20), nullable=False) collection_type = db.Column(db.String(20), nullable=True) current_loan_amount = db.Column(db.Float, nullable=True) initial_loan_amount = db.Column(db.Float, nullable=False) @@ -44,7 +45,7 @@ class Loan(db.Model): ) @classmethod - def create_loan(cls, customer_id, account_id, offer_id, initial_loan_amount, collection_type, transaction_id, status='pending'): + def create_loan(cls, customer_id, account_id, offer_id, product_id, initial_loan_amount, collection_type, transaction_id, status='pending'): # Check if customer exists is_valid = Customer.is_valid_customer(customer_id) diff --git a/app/models/loan_charge.py b/app/models/loan_charge.py index d3f7c2a..0074079 100644 --- a/app/models/loan_charge.py +++ b/app/models/loan_charge.py @@ -14,7 +14,7 @@ class LoanCharge(db.Model): amount = db.Column(db.Float, default=0.0) percent = db.Column(db.Float, default=0.0) description = db.Column(db.Text, nullable=True) - due_date = db.Column(db.DateTime, nullable=False) + due = db.Column(db.Integer, 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)) @@ -36,7 +36,7 @@ class LoanCharge(db.Model): 'amount': self.amount, 'percent': self.percent, 'description': self.description, - 'dueDate': self.due_date.isoformat() if self.due_date else None, + 'due': self.due, } def __repr__(self):