mirror of
https://github.com/frappe/erpnext.git
synced 2026-03-21 11:15:10 +00:00
fix: close employee loan on write off (#37638)
* fix: exclude written off amount while calculating loan repayment * fix: revert exclude written off amount while calculating loan repayment * fix: close employee loan on write off
This commit is contained in:
@@ -411,11 +411,6 @@ def close_unsecured_term_loan(loan):
|
|||||||
frappe.throw(_("Cannot close this loan until full repayment"))
|
frappe.throw(_("Cannot close this loan until full repayment"))
|
||||||
|
|
||||||
|
|
||||||
def close_loan(loan, total_amount_paid):
|
|
||||||
frappe.db.set_value("Loan", loan, "total_amount_paid", total_amount_paid)
|
|
||||||
frappe.db.set_value("Loan", loan, "status", "Closed")
|
|
||||||
|
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def make_loan_disbursement(loan, company, applicant_type, applicant, pending_amount=0, as_dict=0):
|
def make_loan_disbursement(loan, company, applicant_type, applicant, pending_amount=0, as_dict=0):
|
||||||
disbursement_entry = frappe.new_doc("Loan Disbursement")
|
disbursement_entry = frappe.new_doc("Loan Disbursement")
|
||||||
|
|||||||
@@ -9,6 +9,9 @@ from frappe.utils import cint, flt, getdate
|
|||||||
import erpnext
|
import erpnext
|
||||||
from erpnext.accounts.general_ledger import make_gl_entries
|
from erpnext.accounts.general_ledger import make_gl_entries
|
||||||
from erpnext.controllers.accounts_controller import AccountsController
|
from erpnext.controllers.accounts_controller import AccountsController
|
||||||
|
from erpnext.loan_management.doctype.loan_repayment.loan_repayment import (
|
||||||
|
get_pending_principal_amount,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class LoanWriteOff(AccountsController):
|
class LoanWriteOff(AccountsController):
|
||||||
@@ -39,11 +42,13 @@ class LoanWriteOff(AccountsController):
|
|||||||
def on_submit(self):
|
def on_submit(self):
|
||||||
self.update_outstanding_amount()
|
self.update_outstanding_amount()
|
||||||
self.make_gl_entries()
|
self.make_gl_entries()
|
||||||
|
self.close_employee_loan()
|
||||||
|
|
||||||
def on_cancel(self):
|
def on_cancel(self):
|
||||||
self.update_outstanding_amount(cancel=1)
|
self.update_outstanding_amount(cancel=1)
|
||||||
self.ignore_linked_doctypes = ["GL Entry", "Payment Ledger Entry"]
|
self.ignore_linked_doctypes = ["GL Entry", "Payment Ledger Entry"]
|
||||||
self.make_gl_entries(cancel=1)
|
self.make_gl_entries(cancel=1)
|
||||||
|
self.close_employee_loan(cancel=1)
|
||||||
|
|
||||||
def update_outstanding_amount(self, cancel=0):
|
def update_outstanding_amount(self, cancel=0):
|
||||||
written_off_amount = frappe.db.get_value("Loan", self.loan, "written_off_amount")
|
written_off_amount = frappe.db.get_value("Loan", self.loan, "written_off_amount")
|
||||||
@@ -94,3 +99,39 @@ class LoanWriteOff(AccountsController):
|
|||||||
)
|
)
|
||||||
|
|
||||||
make_gl_entries(gl_entries, cancel=cancel, merge_entries=False)
|
make_gl_entries(gl_entries, cancel=cancel, merge_entries=False)
|
||||||
|
|
||||||
|
def close_employee_loan(self, cancel=0):
|
||||||
|
if not frappe.db.has_column("Loan", "repay_from_salary"):
|
||||||
|
return
|
||||||
|
|
||||||
|
loan = frappe.get_value(
|
||||||
|
"Loan",
|
||||||
|
self.loan,
|
||||||
|
[
|
||||||
|
"total_payment",
|
||||||
|
"total_principal_paid",
|
||||||
|
"loan_amount",
|
||||||
|
"total_interest_payable",
|
||||||
|
"written_off_amount",
|
||||||
|
"disbursed_amount",
|
||||||
|
"status",
|
||||||
|
"is_secured_loan",
|
||||||
|
"repay_from_salary",
|
||||||
|
"name",
|
||||||
|
],
|
||||||
|
as_dict=1,
|
||||||
|
)
|
||||||
|
|
||||||
|
if loan.is_secured_loan or not loan.repay_from_salary:
|
||||||
|
return
|
||||||
|
|
||||||
|
if not cancel:
|
||||||
|
pending_principal_amount = get_pending_principal_amount(loan)
|
||||||
|
|
||||||
|
precision = cint(frappe.db.get_default("currency_precision")) or 2
|
||||||
|
|
||||||
|
if flt(pending_principal_amount, precision) <= 0:
|
||||||
|
frappe.db.set_value("Loan", loan.name, "status", "Closed")
|
||||||
|
frappe.msgprint(_("Loan {0} closed").format(loan.name))
|
||||||
|
else:
|
||||||
|
frappe.db.set_value("Loan", loan.loan, "status", "Disbursed")
|
||||||
|
|||||||
Reference in New Issue
Block a user