feat: Auto accrue loan interest for backdated term loans
This commit is contained in:
parent
cb8cd7f5bc
commit
96d8b1ef3c
@ -68,6 +68,8 @@ class Loan(AccountsController):
|
||||
|
||||
def on_submit(self):
|
||||
self.link_loan_security_pledge()
|
||||
# Interest accrual for backdated term loans
|
||||
self.accrue_loan_interest()
|
||||
|
||||
def on_cancel(self):
|
||||
self.unlink_loan_security_pledge()
|
||||
@ -187,6 +189,16 @@ class Loan(AccountsController):
|
||||
|
||||
self.db_set("maximum_loan_amount", maximum_loan_value)
|
||||
|
||||
def accrue_loan_interest(self):
|
||||
from erpnext.loan_management.doctype.process_loan_interest_accrual.process_loan_interest_accrual import (
|
||||
process_loan_interest_accrual_for_term_loans,
|
||||
)
|
||||
|
||||
if getdate(self.repayment_start_date) < getdate() and self.is_term_loan:
|
||||
process_loan_interest_accrual_for_term_loans(
|
||||
posting_date=getdate(), loan_type=self.loan_type, loan=self.name
|
||||
)
|
||||
|
||||
def unlink_loan_security_pledge(self):
|
||||
pledges = frappe.get_all("Loan Security Pledge", fields=["name"], filters={"loan": self.name})
|
||||
pledge_list = [d.name for d in pledges]
|
||||
|
@ -29,6 +29,9 @@ from erpnext.loan_management.doctype.loan_repayment.loan_repayment import (
|
||||
calculate_amounts,
|
||||
create_repayment_entry,
|
||||
)
|
||||
from erpnext.loan_management.doctype.process_loan_interest_accrual.process_loan_interest_accrual import (
|
||||
process_loan_interest_accrual_for_term_loans,
|
||||
)
|
||||
from erpnext.payroll.doctype.additional_salary.additional_salary import get_additional_salaries
|
||||
from erpnext.payroll.doctype.employee_benefit_application.employee_benefit_application import (
|
||||
get_benefit_component_amount,
|
||||
@ -1364,9 +1367,9 @@ class SalarySlip(TransactionBase):
|
||||
self.total_loan_repayment += payment.total_payment
|
||||
|
||||
def get_loan_details(self):
|
||||
return frappe.get_all(
|
||||
loan_details = frappe.get_all(
|
||||
"Loan",
|
||||
fields=["name", "interest_income_account", "loan_account", "loan_type"],
|
||||
fields=["name", "interest_income_account", "loan_account", "loan_type", "is_term_loan"],
|
||||
filters={
|
||||
"applicant": self.employee,
|
||||
"docstatus": 1,
|
||||
@ -1375,6 +1378,15 @@ class SalarySlip(TransactionBase):
|
||||
},
|
||||
)
|
||||
|
||||
if loan_details:
|
||||
for loan in loan_details:
|
||||
if loan.is_term_loan:
|
||||
process_loan_interest_accrual_for_term_loans(
|
||||
posting_date=self.posting_date, loan_type=loan.loan_type, loan=loan.name
|
||||
)
|
||||
|
||||
return loan_details
|
||||
|
||||
def make_loan_repayment_entry(self):
|
||||
payroll_payable_account = get_payroll_payable_account(self.company, self.payroll_entry)
|
||||
for loan in self.loans:
|
||||
|
Loading…
x
Reference in New Issue
Block a user