fix: pending principal- amount

This commit is contained in:
Abhinav Raut 2022-08-04 19:04:34 +05:30
parent c95b986414
commit a272d73dd9
8 changed files with 39 additions and 14 deletions

View File

@ -99,7 +99,7 @@ class LoanBalanceAdjustment(AccountsController):
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,

View File

@ -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",
@ -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",

View File

@ -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",

View File

@ -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",

View File

@ -264,11 +264,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",
@ -294,7 +294,7 @@
"index_web_pages_for_search": 1,
"is_submittable": 1,
"links": [],
"modified": "2022-06-21 10:10:07.742298",
"modified": "2022-08-04 17:13:51.964203",
"modified_by": "Administrator",
"module": "Loan Management",
"name": "Loan Repayment",

View File

@ -149,6 +149,9 @@ class LoanRepayment(AccountsController):
"status",
"is_secured_loan",
"total_payment",
"debit_adjustment_amount",
"credit_adjustment_amount",
"refund_amount",
"loan_amount",
"disbursed_amount",
"total_interest_payable",
@ -398,7 +401,7 @@ class LoanRepayment(AccountsController):
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 hasattr(self, "repay_from_salary") and self.repay_from_salary:
payment_account = self.payroll_payable_account

View File

@ -57,6 +57,9 @@ class LoanSecurityUnpledge(Document):
self.loan,
[
"total_payment",
"debit_adjustment_amount",
"credit_adjustment_amount",
"refund_amount",
"total_principal_paid",
"loan_amount",
"total_interest_payable",

View File

@ -9,6 +9,9 @@ from frappe.utils import cint, flt, getdate
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):
@ -22,16 +25,26 @@ class LoanWriteOff(AccountsController):
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"))