salary process apart
This commit is contained in:
+19
-21
@@ -129,12 +129,24 @@ def salary_detect():
|
||||
if payload:
|
||||
# Step 1: Try to add new salary data
|
||||
try:
|
||||
new_salary = SalaryService.add_salary_data(payload)
|
||||
new_salary = SalaryService.add_salary_data(payload) # TODO - This will come as array of salaries - not just one
|
||||
if new_salary:
|
||||
logger.info(f"Salary added: {new_salary.id}")
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to save salary: {e}")
|
||||
|
||||
process_salary_list() # TODO - This should be threaded out or removed from here finally
|
||||
|
||||
logger.info(f"Finished processing List")
|
||||
return ResponseHelper.success([], "AutoCall Add Salary Successful")
|
||||
|
||||
@autocall_bp.route("/analytic-salary-process", methods=["POST"])
|
||||
def salary_process():
|
||||
response = process_salary_list()
|
||||
return ResponseHelper.success([], "AutoCall Successful")
|
||||
|
||||
|
||||
def process_salary_list():
|
||||
# Step 2: Get all pending salaries
|
||||
pending_salaries = SalaryService.get_pending_salaries()
|
||||
if not pending_salaries:
|
||||
@@ -168,47 +180,33 @@ def salary_detect():
|
||||
for loan in loans:
|
||||
logger.info(f"Loan LOOP LoanID = :{loan.id}")
|
||||
try:
|
||||
#loan_dict = loan.to_dict()
|
||||
# loan_dict = loan.to_dict()
|
||||
logger.info(f"loan_dict ==== Repayment Data:{loan}")
|
||||
repayment_data = {
|
||||
"customerId": loan.customer_id,
|
||||
"loanId": loan.id ,
|
||||
"productId": loan.product_id ,
|
||||
"loanId": loan.id,
|
||||
"productId": loan.product_id,
|
||||
"transactionId": loan.transaction_id,
|
||||
"initiatedBy": "SALARY_DETECT",
|
||||
"salaryAmount": pending_salary.amount,
|
||||
"LoanStatus": loan.status,
|
||||
}
|
||||
|
||||
# repayment_data = {
|
||||
# "customerId": loan.customer_id,
|
||||
# "loanId": loan_dict["debtId"],
|
||||
# "productId": loan_dict["productId"],
|
||||
# "transactionId": loan_dict["transactionId"],
|
||||
# "initiatedBy": "SALARY_DETECT",
|
||||
# "salaryAmount": pending_salary.amount,
|
||||
# }
|
||||
#
|
||||
logger.info(f"Saving/Creating Repayment Data:{repayment_data}")
|
||||
#logger.info(f"Creating repayment for loan ID {loan_dict['debtId']}")
|
||||
# repayment = RepaymentService.add_repayment(repayment_data)
|
||||
repayment = RepaymentService.create_repayment(repayment_data)
|
||||
LoanService.update_status(loan_id=repayment_data["loanId"],
|
||||
status=LoanStatus.START_REPAY) # repay started
|
||||
status=LoanStatus.START_REPAY) # repay started
|
||||
|
||||
logger.info(f"Created repayment ID: {repayment.id}")
|
||||
except Exception as e:
|
||||
logger.error(f"Error creating repayment for loan ID {loan.id}: {e}")
|
||||
continue
|
||||
# Step 4: Simbrella integration call after all processing
|
||||
# Step 4: Simbrella integration call after all processing
|
||||
try:
|
||||
SimbrellaClient.collect_loan_user_salary_detect(repayment.to_dict())
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to call Simbrella client: {e}")
|
||||
|
||||
|
||||
|
||||
logger.info(f"Finished processing salary ID: {pending_salary.id}")
|
||||
return ResponseHelper.success([], "AutoCall Successful")
|
||||
return []
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user