From b58590251b4537c9c1a927312f3ba1e633e8e746 Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Sat, 10 Apr 2021 19:55:36 +0530 Subject: [PATCH] fix: minor improvements and tests --- .../loan_management/doctype/loan/loan.json | 9 ++++++- .../loan_management/doctype/loan/test_loan.py | 6 ++--- .../loan_disbursement/loan_disbursement.json | 25 ++++++++++++++++++- .../loan_repayment/loan_repayment.json | 6 +++-- .../doctype/loan_repayment/loan_repayment.py | 12 +++++++-- .../loan_security_unpledge.py | 8 ++++-- 6 files changed, 55 insertions(+), 11 deletions(-) diff --git a/erpnext/loan_management/doctype/loan/loan.json b/erpnext/loan_management/doctype/loan/loan.json index acf09f5c03..4f8ceb0de8 100644 --- a/erpnext/loan_management/doctype/loan/loan.json +++ b/erpnext/loan_management/doctype/loan/loan.json @@ -23,6 +23,7 @@ "rate_of_interest", "is_secured_loan", "disbursement_date", + "closure_date", "disbursed_amount", "column_break_11", "maximum_loan_amount", @@ -348,12 +349,18 @@ "no_copy": 1, "options": "Company:company:default_currency", "read_only": 1 + }, + { + "fieldname": "closure_date", + "fieldtype": "Date", + "label": "Closure Date", + "read_only": 1 } ], "index_web_pages_for_search": 1, "is_submittable": 1, "links": [], - "modified": "2020-11-24 12:27:23.208240", + "modified": "2021-04-10 09:28:21.946972", "modified_by": "Administrator", "module": "Loan Management", "name": "Loan", diff --git a/erpnext/loan_management/doctype/loan/test_loan.py b/erpnext/loan_management/doctype/loan/test_loan.py index 57f98869cc..6f8da3166f 100644 --- a/erpnext/loan_management/doctype/loan/test_loan.py +++ b/erpnext/loan_management/doctype/loan/test_loan.py @@ -523,7 +523,7 @@ class TestLoan(unittest.TestCase): self.assertEqual(flt(repayment_entry.total_interest_paid, 0), flt(interest_amount, 0)) def test_penalty(self): - loan = create_loan_scenario_for_penalty(self) + loan, amounts = create_loan_scenario_for_penalty(self) # 30 days - grace period penalty_days = 30 - 4 penalty_applicable_amount = flt(amounts['interest_amount']/2) @@ -537,7 +537,7 @@ class TestLoan(unittest.TestCase): self.assertEquals(calculated_penalty_amount, penalty_amount) def test_penalty_repayment(self): - loan = create_loan_scenario_for_penalty(self) + loan, dummy = create_loan_scenario_for_penalty(self) amounts = calculate_amounts(loan.name, '2019-11-30 00:00:00') first_penalty = 10000 @@ -670,7 +670,7 @@ def create_loan_scenario_for_penalty(doc): repayment_entry.submit() - return loan + return loan, amounts def create_loan_accounts(): if not frappe.db.exists("Account", "Loans and Advances (Assets) - _TC"): diff --git a/erpnext/loan_management/doctype/loan_disbursement/loan_disbursement.json b/erpnext/loan_management/doctype/loan_disbursement/loan_disbursement.json index cd5df4d3cd..662c626b8d 100644 --- a/erpnext/loan_management/doctype/loan_disbursement/loan_disbursement.json +++ b/erpnext/loan_management/doctype/loan_disbursement/loan_disbursement.json @@ -20,6 +20,10 @@ "cost_center", "customer_details_section", "bank_account", + "disbursement_references_section", + "reference_date", + "column_break_17", + "reference_number", "amended_from" ], "fields": [ @@ -126,12 +130,31 @@ { "fieldname": "column_break_8", "fieldtype": "Column Break" + }, + { + "fieldname": "disbursement_references_section", + "fieldtype": "Section Break", + "label": "Disbursement References" + }, + { + "fieldname": "reference_date", + "fieldtype": "Date", + "label": "Reference Date" + }, + { + "fieldname": "column_break_17", + "fieldtype": "Column Break" + }, + { + "fieldname": "reference_number", + "fieldtype": "Data", + "label": "Reference Number" } ], "index_web_pages_for_search": 1, "is_submittable": 1, "links": [], - "modified": "2020-11-06 10:04:30.882322", + "modified": "2021-04-10 10:03:41.502210", "modified_by": "Administrator", "module": "Loan Management", "name": "Loan Disbursement", diff --git a/erpnext/loan_management/doctype/loan_repayment/loan_repayment.json b/erpnext/loan_management/doctype/loan_repayment/loan_repayment.json index 86ea59dc24..8fbf233be5 100644 --- a/erpnext/loan_management/doctype/loan_repayment/loan_repayment.json +++ b/erpnext/loan_management/doctype/loan_repayment/loan_repayment.json @@ -239,14 +239,16 @@ { "fieldname": "total_penalty_paid", "fieldtype": "Currency", + "hidden": 1, "label": "Total Penalty Paid", - "options": "Company:company:default_currency" + "options": "Company:company:default_currency", + "read_only": 1 } ], "index_web_pages_for_search": 1, "is_submittable": 1, "links": [], - "modified": "2021-04-05 13:45:19.137896", + "modified": "2021-04-10 10:00:31.859076", "modified_by": "Administrator", "module": "Loan Management", "name": "Loan Repayment", diff --git a/erpnext/loan_management/doctype/loan_repayment/loan_repayment.py b/erpnext/loan_management/doctype/loan_repayment/loan_repayment.py index baa45a4704..728eadf22a 100644 --- a/erpnext/loan_management/doctype/loan_repayment/loan_repayment.py +++ b/erpnext/loan_management/doctype/loan_repayment/loan_repayment.py @@ -227,6 +227,14 @@ class LoanRepayment(AccountsController): gle_map = [] loan_details = frappe.get_doc("Loan", self.against_loan) + if self.shortfall_amount and self.amount_paid > self.shortfall_amount: + remarks = _("Shortfall Repayment of {0}.\nRepayment against Loan: {1}").format(self.shortfall_amount, + self.against_loan) + elif self.shortfall_amount: + remarks = _("Shortfall Repayment of {0}").format(self.shortfall_amount) + else: + remarks = _("Repayment against Loan: ") + self.against_loan + if self.total_penalty_paid: gle_map.append( self.get_gl_dict({ @@ -267,7 +275,7 @@ class LoanRepayment(AccountsController): "debit_in_account_currency": self.amount_paid, "against_voucher_type": "Loan", "against_voucher": self.against_loan, - "remarks": _("Repayment against Loan: ") + self.against_loan, + "remarks": remarks, "cost_center": self.cost_center, "posting_date": getdate(self.posting_date) }) @@ -283,7 +291,7 @@ class LoanRepayment(AccountsController): "credit_in_account_currency": self.amount_paid, "against_voucher_type": "Loan", "against_voucher": self.against_loan, - "remarks": _("Repayment against Loan: ") + self.against_loan, + "remarks": remarks, "cost_center": self.cost_center, "posting_date": getdate(self.posting_date) }) diff --git a/erpnext/loan_management/doctype/loan_security_unpledge/loan_security_unpledge.py b/erpnext/loan_management/doctype/loan_security_unpledge/loan_security_unpledge.py index c4c2d68378..b24dc2f7c2 100644 --- a/erpnext/loan_management/doctype/loan_security_unpledge/loan_security_unpledge.py +++ b/erpnext/loan_management/doctype/loan_security_unpledge/loan_security_unpledge.py @@ -6,7 +6,7 @@ from __future__ import unicode_literals import frappe from frappe import _ from frappe.model.document import Document -from frappe.utils import get_datetime, flt +from frappe.utils import get_datetime, flt, getdate import json from six import iteritems from erpnext.loan_management.doctype.loan_security_price.loan_security_price import get_loan_security_price @@ -113,7 +113,11 @@ class LoanSecurityUnpledge(Document): pledged_qty += qty if not pledged_qty: - frappe.db.set_value('Loan', self.loan, 'status', 'Closed') + frappe.db.set_value('Loan', self.loan, + { + 'status': 'Closed', + 'closure_date': getdate() + }) @frappe.whitelist() def get_pledged_security_qty(loan):