Skip to content

Commit

Permalink
Merge pull request #31783 from frappe/mergify/bp/version-13-hotfix/pr…
Browse files Browse the repository at this point in the history
…-31780

Fix: Loan pending principal amount  (backport #31780)
  • Loading branch information
deepeshgarg007 authored Aug 8, 2022
2 parents 0e46b33 + fb37257 commit 3673dea
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def make_gl_entries(self, cancel=0, adv_adj=0):
loan_account = frappe.db.get_value("Loan", self.loan, "loan_account")
remarks = "{} against loan {}".format(self.adjustment_type.capitalize(), self.loan)
if self.reference_number:
remarks += "with reference no. {}".format(self.reference_number)
remarks += " with reference no. {}".format(self.reference_number)

loan_entry = {
"account": loan_account,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,11 @@
},
{
"fetch_from": "against_loan.disbursement_account",
"fetch_if_empty": 1,
"fieldname": "disbursement_account",
"fieldtype": "Link",
"label": "Disbursement Account",
"options": "Account",
"read_only": 1
"options": "Account"
},
{
"fieldname": "column_break_16",
Expand All @@ -185,7 +185,7 @@
"index_web_pages_for_search": 1,
"is_submittable": 1,
"links": [],
"modified": "2022-02-17 18:23:44.157598",
"modified": "2022-08-04 17:16:04.922444",
"modified_by": "Administrator",
"module": "Loan Management",
"name": "Loan Disbursement",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,9 @@ def get_disbursal_amount(loan, on_current_security_price=0):
"loan_amount",
"disbursed_amount",
"total_payment",
"debit_adjustment_amount",
"credit_adjustment_amount",
"refund_amount",
"total_principal_paid",
"total_interest_payable",
"status",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ def make_accrual_interest_entry_for_demand_loans(
"name",
"total_payment",
"total_amount_paid",
"debit_adjustment_amount",
"credit_adjustment_amount",
"refund_amount",
"loan_account",
"interest_income_account",
"loan_amount",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,11 +281,11 @@
},
{
"fetch_from": "against_loan.payment_account",
"fetch_if_empty": 1,
"fieldname": "payment_account",
"fieldtype": "Link",
"label": "Repayment Account",
"options": "Account",
"read_only": 1
"options": "Account"
},
{
"fieldname": "column_break_36",
Expand All @@ -311,7 +311,7 @@
"index_web_pages_for_search": 1,
"is_submittable": 1,
"links": [],
"modified": "2022-02-18 19:10:07.742298",
"modified": "2022-08-04 17:13:51.964203",
"modified_by": "Administrator",
"module": "Loan Management",
"name": "Loan Repayment",
Expand Down Expand Up @@ -353,4 +353,4 @@
"sort_order": "DESC",
"states": [],
"track_changes": 1
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@ def update_paid_amount(self):
"status",
"is_secured_loan",
"total_payment",
"debit_adjustment_amount",
"credit_adjustment_amount",
"refund_amount",
"loan_amount",
"disbursed_amount",
"total_interest_payable",
Expand Down Expand Up @@ -399,7 +402,7 @@ def make_gl_entries(self, cancel=0, adv_adj=0):
remarks = "Repayment against loan " + self.against_loan

if self.reference_number:
remarks += "with reference no. {}".format(self.reference_number)
remarks += " with reference no. {}".format(self.reference_number)

if self.repay_from_salary:
payment_account = self.payroll_payable_account
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ def validate_unpledge_qty(self):
self.loan,
[
"total_payment",
"debit_adjustment_amount",
"credit_adjustment_amount",
"refund_amount",
"total_principal_paid",
"loan_amount",
"total_interest_payable",
Expand Down
25 changes: 19 additions & 6 deletions erpnext/loan_management/doctype/loan_write_off/loan_write_off.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
import erpnext
from erpnext.accounts.general_ledger import make_gl_entries
from erpnext.controllers.accounts_controller import AccountsController
from erpnext.loan_management.doctype.loan_repayment.loan_repayment import (
get_pending_principal_amount,
)


class LoanWriteOff(AccountsController):
Expand All @@ -22,16 +25,26 @@ def set_missing_values(self):

def validate_write_off_amount(self):
precision = cint(frappe.db.get_default("currency_precision")) or 2
total_payment, principal_paid, interest_payable, written_off_amount = frappe.get_value(

loan_details = frappe.get_value(
"Loan",
self.loan,
["total_payment", "total_principal_paid", "total_interest_payable", "written_off_amount"],
[
"total_payment",
"debit_adjustment_amount",
"credit_adjustment_amount",
"refund_amount",
"total_principal_paid",
"loan_amount",
"total_interest_payable",
"written_off_amount",
"disbursed_amount",
"status",
],
as_dict=1,
)

pending_principal_amount = flt(
flt(total_payment) - flt(interest_payable) - flt(principal_paid) - flt(written_off_amount),
precision,
)
pending_principal_amount = flt(get_pending_principal_amount(loan_details), precision)

if self.write_off_amount > pending_principal_amount:
frappe.throw(_("Write off amount cannot be greater than pending principal amount"))
Expand Down

0 comments on commit 3673dea

Please sign in to comment.