Skip to content

Commit

Permalink
fix: cancell loan repayment on fnf cancellation
Browse files Browse the repository at this point in the history
  • Loading branch information
AyshaHakeem committed Jan 15, 2025
1 parent a0b56e1 commit a77be53
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
from frappe.model.document import Document
from frappe.utils import flt, get_link_to_form, today

from hrms.hr.doctype.full_and_final_statement.full_and_final_statement_loan_utils import process_loan_accrual
from hrms.hr.doctype.full_and_final_statement.full_and_final_statement_loan_utils import (
cancel_loan_repayment,
process_loan_accrual,
)


class FullandFinalStatement(Document):
Expand All @@ -28,7 +31,8 @@ def on_submit(self):
process_loan_accrual(self)

def on_cancel(self):
self.ignore_linked_doctypes = ("GL Entry",)
self.ignore_linked_doctypes = "GL Entry"
cancel_loan_repayment(self)

def validate_relieving_date(self):
if not self.relieving_date:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ def process_loan_accrual(doc: "FullandFinalStatement"):

loan_receivables.append(receivable.reference_document)

loan_receivables = list(set(loan_receivables))

for loan in loan_receivables:
loan_doc = frappe.get_doc("Loan", loan)
loan_repayment_schedule = frappe.get_doc("Loan Repayment Schedule", {"loan": loan, "docstatus": 1})
Expand Down Expand Up @@ -76,3 +74,29 @@ def process_loan_accrual(doc: "FullandFinalStatement"):

repayment_entry.save()
repayment_entry.submit()


@if_lending_app_installed
def cancel_loan_repayment(doc: "FullandFinalStatement"):
loan_receivables = []
for receivable in doc.receivables:
if receivable.component != "Loan":
continue

loan_receivables.append(receivable.reference_document)

# loan_receivables = list(set(loan_receivables))
for loan in loan_receivables:
posting_date = frappe.utils.getdate(doc.transaction_date)
loan_repayment = frappe.get_doc(
"Loan Repayment", {"against_loan": loan, "docstatus": 1, "posting_date": posting_date}
)

if loan_repayment:
loan_repayment.cancel()

loan_interest_accruals = frappe.get_all(
"Loan Interest Accrual", filters={"loan": loan, "docstatus": 1, "posting_date": posting_date}
)
for accrual in loan_interest_accruals:
frappe.get_doc("Loan Interest Accrual", accrual.name).cancel()

0 comments on commit a77be53

Please sign in to comment.