Linked loan design
This commit is contained in:
@@ -35,7 +35,7 @@ class SimbrellaIntegration:
|
||||
],
|
||||
}
|
||||
|
||||
logger.info(f"This is PayLoad: {str(payload)}", exc_info=True)
|
||||
# logger.info(f"This is PayLoad: {str(payload)}", exc_info=True)
|
||||
|
||||
headers = {
|
||||
"Content-Type": "application/json",
|
||||
|
||||
@@ -87,7 +87,7 @@ class EligibilityCheckService(BaseService):
|
||||
transaction_id=transactionId,
|
||||
rac_check=rac_check,
|
||||
validated_data=validated_data,
|
||||
customer=customer
|
||||
customer_id=customer_id
|
||||
)
|
||||
except ValueError as ve:
|
||||
logger.error(str(ve))
|
||||
|
||||
@@ -34,34 +34,63 @@ class OfferAnalysis:
|
||||
return transaction_offer, offer, eligible_amount, original_transaction
|
||||
|
||||
@staticmethod
|
||||
def decide_offer(transaction_id, rac_check, validated_data, customer):
|
||||
|
||||
def decide_offer(transaction_id, rac_check, validated_data, customer_id):
|
||||
eligible_offers = []
|
||||
# if we have active offers - we have to feed off it
|
||||
logger.info(f"LOOOOOOOOOOOOOOOOOO** {customer_id}")
|
||||
|
||||
# we can now find the origin transactions
|
||||
# Find the last loan - it will have original_transaction
|
||||
# last_customer_loan = Loan.get_customer_last_loan(customer.id)
|
||||
last_customer_loan = Loan.get_customer_last_loan(customer_id)
|
||||
# logger.info(f"{last_customer_loan}")
|
||||
|
||||
new_eligible_amount = 0
|
||||
|
||||
# if last_customer_loan:
|
||||
# original_transaction = last_customer_loan.original_transaction or last_customer_loan.transaction_id
|
||||
if last_customer_loan:
|
||||
original_transaction = last_customer_loan.original_transaction or last_customer_loan.transaction_id
|
||||
logger.info(f"transaction_id |-| original_transaction === > {transaction_id} {original_transaction}")
|
||||
original_loan = Loan.get_customer_original_loan(customer_id, original_transaction)
|
||||
if original_loan is not None:
|
||||
logger.info(f"original_loan === > {original_loan}")
|
||||
logger.info(f"loan_offer_id === > {original_loan.offer_id}")
|
||||
|
||||
# real_eligible_amount = last_customer_loan.eligible_amount
|
||||
original_offer_id = str(original_loan.offer_id[:5]) # The last part is str
|
||||
transaction_offer_id = int(original_loan.offer_id[5:]) # The last part is int
|
||||
original_transaction_offer = TransactionOffer.is_valid_transaction_offer(transaction_offer_id, customer_id, original_loan.product_id)
|
||||
|
||||
# active_loans = Loan.get_active_loans_by_original_transaction(original_transaction)
|
||||
active_loans = Loan.get_active_loans_by_original_transaction(original_transaction)
|
||||
sum_active_loans = sum(loan.current_loan_amount for loan in active_loans)
|
||||
logger.info(f"sum_active_loans === > {sum_active_loans}")
|
||||
real_eligible_amount = original_loan.eligible_amount - sum_active_loans
|
||||
|
||||
# sum_active_loans = sum(loan.current_loan_amount for loan in active_loans)
|
||||
|
||||
# new_eligible_amount = max(real_eligible_amount - sum_active_loans, 0)
|
||||
transaction_offer = TransactionOffer.create_transaction_offer(
|
||||
customer_id=customer_id,
|
||||
transaction_id=transaction_id,
|
||||
original_transaction=original_transaction,
|
||||
offer_id=original_offer_id,
|
||||
min_amount=original_transaction_offer.min_amount,
|
||||
max_amount=original_transaction_offer.max_amount,
|
||||
eligible_amount=real_eligible_amount,
|
||||
product_id=original_loan.product_id,
|
||||
tenor=original_loan.tenor
|
||||
)
|
||||
|
||||
# logger.info(f"Real eligible: {real_eligible_amount}, Sum of active: {sum_active_loans}, New eligible: {new_eligible_amount}")
|
||||
# Visible offer ID: offer_id + padded(transaction_offer.id)
|
||||
padded_id = str(transaction_offer.id).zfill(6)
|
||||
public_offer_id = f"{original_offer_id}{padded_id}"
|
||||
|
||||
eligible_offers.append({
|
||||
"offerId": public_offer_id,
|
||||
"product_id": original_transaction_offer.product_id,
|
||||
"min_amount": original_transaction_offer.min_amount,
|
||||
"max_amount": real_eligible_amount,
|
||||
"tenor": original_loan.tenor
|
||||
})
|
||||
return eligible_offers
|
||||
|
||||
# Construct eligible_offers
|
||||
|
||||
offers = Offer.get_all_offers()
|
||||
eligible_offers = []
|
||||
|
||||
|
||||
for offer in offers:
|
||||
# Get approved amount
|
||||
@@ -71,7 +100,7 @@ class OfferAnalysis:
|
||||
approved_amount = round(approved_amount, 2)
|
||||
|
||||
transaction_offer = TransactionOffer.create_transaction_offer(
|
||||
customer_id=customer.id,
|
||||
customer_id=customer_id,
|
||||
transaction_id=transaction_id,
|
||||
original_transaction=transaction_id,
|
||||
offer_id=offer.id,
|
||||
|
||||
Reference in New Issue
Block a user