Skip to content

Commit 1f4884e

Browse files
Merge pull request #109 from frappe/mergify/copy/poc-staging/pr-108
feat: Assign multiple securities to one loan (#108)
2 parents 8701c6a + 4db813e commit 1f4884e

31 files changed

+214
-137
lines changed

lending/loan_management/doctype/loan/loan.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ frappe.ui.form.on('Loan', {
77
setup: function(frm) {
88
frm.make_methods = {
99
'Loan Disbursement': function() { frm.trigger('make_loan_disbursement') },
10-
'Loan Security Unpledge': function() { frm.trigger('create_loan_security_unpledge') },
10+
'Loan Security Release': function() { frm.trigger('create_loan_security_unpledge') },
1111
'Loan Write Off': function() { frm.trigger('make_loan_write_off_entry') }
1212
}
1313
},
1414
onload: function (frm) {
1515
// Ignore loan security pledge on cancel of loan
16-
frm.ignore_doctypes_on_cancel_all = ["Loan Security Pledge", "Loan Repayment Schedule"];
16+
frm.ignore_doctypes_on_cancel_all = ["Loan Security Assignment", "Loan Repayment Schedule"];
1717

1818
frm.set_query("loan_application", function () {
1919
return {
@@ -82,7 +82,7 @@ frappe.ui.form.on('Loan', {
8282
}
8383

8484
if (frm.doc.status == "Loan Closure Requested") {
85-
frm.add_custom_button(__('Loan Security Unpledge'), function() {
85+
frm.add_custom_button(__('Loan Security Release'), function() {
8686
frm.trigger("create_loan_security_unpledge");
8787
},__('Create'));
8888
}

lending/loan_management/doctype/loan/loan.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
from erpnext.accounts.doctype.journal_entry.journal_entry import get_payment_entry
2323
from erpnext.controllers.accounts_controller import AccountsController
2424

25-
from lending.loan_management.doctype.loan_security_unpledge.loan_security_unpledge import (
25+
from lending.loan_management.doctype.loan_security_release.loan_security_release import (
2626
get_pledged_security_qty,
2727
)
2828

@@ -244,7 +244,7 @@ def validate_loan_amount(self):
244244
def link_loan_security_pledge(self):
245245
if self.is_secured_loan and self.loan_application:
246246
maximum_loan_value = frappe.db.get_value(
247-
"Loan Security Pledge",
247+
"Loan Security Assignment",
248248
{"loan_application": self.loan_application, "status": "Requested"},
249249
"sum(maximum_loan_value)",
250250
)
@@ -272,7 +272,9 @@ def accrue_loan_interest(self):
272272
)
273273

274274
def unlink_loan_security_pledge(self):
275-
pledges = frappe.get_all("Loan Security Pledge", fields=["name"], filters={"loan": self.name})
275+
pledges = frappe.get_all(
276+
"Loan Security Assignment", fields=["name"], filters={"loan": self.name}
277+
)
276278
pledge_list = [d.name for d in pledges]
277279
if pledge_list:
278280
frappe.db.sql(
@@ -513,7 +515,7 @@ def unpledge_security(
513515
# will unpledge qty based on loan security pledge
514516
elif loan_security_pledge:
515517
security_map = {}
516-
pledge_doc = frappe.get_doc("Loan Security Pledge", loan_security_pledge)
518+
pledge_doc = frappe.get_doc("Loan Security Assignment", loan_security_pledge)
517519
for security in pledge_doc.securities:
518520
security_map.setdefault(security.loan_security, security.qty)
519521

@@ -545,7 +547,7 @@ def unpledge_security(
545547

546548

547549
def create_loan_security_unpledge(unpledge_map, loan, company, applicant_type, applicant):
548-
unpledge_request = frappe.new_doc("Loan Security Unpledge")
550+
unpledge_request = frappe.new_doc("Loan Security Release")
549551
unpledge_request.applicant_type = applicant_type
550552
unpledge_request.applicant = applicant
551553
unpledge_request.loan = loan

lending/loan_management/doctype/loan/loan_dashboard.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ def get_data():
1010
{
1111
"items": [
1212
"Loan Repayment Schedule",
13-
"Loan Security Pledge",
13+
"Loan Security Assignment",
1414
"Loan Security Shortfall",
1515
"Loan Disbursement",
1616
]
1717
},
1818
{"items": ["Loan Repayment", "Loan Interest Accrual", "Loan Write Off", "Loan Restructure"]},
19-
{"items": ["Loan Security Unpledge", "Days Past Due Log", "Journal Entry", "Sales Invoice"]},
19+
{"items": ["Loan Security Release", "Days Past Due Log", "Journal Entry", "Sales Invoice"]},
2020
],
2121
}

lending/loan_management/doctype/loan/test_loan.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
days_in_year,
3232
)
3333
from lending.loan_management.doctype.loan_repayment.loan_repayment import calculate_amounts
34-
from lending.loan_management.doctype.loan_security_unpledge.loan_security_unpledge import (
34+
from lending.loan_management.doctype.loan_security_release.loan_security_release import (
3535
get_pledged_security_qty,
3636
)
3737
from lending.loan_management.doctype.process_loan_interest_accrual.process_loan_interest_accrual import (
@@ -1146,7 +1146,7 @@ def create_loan_security():
11461146

11471147
def create_loan_security_pledge(applicant, pledges, loan_application=None, loan=None):
11481148

1149-
lsp = frappe.new_doc("Loan Security Pledge")
1149+
lsp = frappe.new_doc("Loan Security Assignment")
11501150
lsp.applicant_type = "Customer"
11511151
lsp.applicant = applicant
11521152
lsp.company = "_Test Company"

lending/loan_management/doctype/loan_application/loan_application.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ frappe.ui.form.on('Loan Application', {
88
setup: function(frm) {
99
frm.make_methods = {
1010
'Loan': function() { frm.trigger('create_loan') },
11-
'Loan Security Pledge': function() { frm.trigger('create_loan_security_pledge') },
11+
'Loan Security Assignment': function() { frm.trigger('create_loan_security_pledge') },
1212
}
1313
},
1414
refresh: function(frm) {
@@ -39,9 +39,9 @@ frappe.ui.form.on('Loan Application', {
3939
if (frm.doc.status == "Approved") {
4040

4141
if (frm.doc.is_secured_loan) {
42-
frappe.db.get_value("Loan Security Pledge", {"loan_application": frm.doc.name, "docstatus": 1}, "name", (r) => {
42+
frappe.db.get_value("Loan Security Assignment", {"loan_application": frm.doc.name, "docstatus": 1}, "name", (r) => {
4343
if (Object.keys(r).length === 0) {
44-
frm.add_custom_button(__('Loan Security Pledge'), function() {
44+
frm.add_custom_button(__('Loan Security Assignment'), function() {
4545
frm.trigger('create_loan_security_pledge');
4646
},__('Create'))
4747
}
@@ -72,7 +72,7 @@ frappe.ui.form.on('Loan Application', {
7272
create_loan_security_pledge: function(frm) {
7373

7474
if(!frm.doc.is_secured_loan) {
75-
frappe.throw(__("Loan Security Pledge can only be created for secured loans"));
75+
frappe.throw(__("Loan Security Assignment can only be created for secured loans"));
7676
}
7777

7878
frappe.call({
@@ -81,7 +81,7 @@ frappe.ui.form.on('Loan Application', {
8181
loan_application: frm.doc.name
8282
},
8383
callback: function(r) {
84-
frappe.set_route("Form", "Loan Security Pledge", r.message);
84+
frappe.set_route("Form", "Loan Security Assignment", r.message);
8585
}
8686
})
8787
},

lending/loan_management/doctype/loan_application/loan_application.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ def update_accounts(source_doc, target_doc, source_parent):
203203
def create_pledge(loan_application, loan=None):
204204
loan_application_doc = frappe.get_doc("Loan Application", loan_application)
205205

206-
lsp = frappe.new_doc("Loan Security Pledge")
206+
lsp = frappe.new_doc("Loan Security Assignment")
207207
lsp.applicant_type = loan_application_doc.applicant_type
208208
lsp.applicant = loan_application_doc.applicant
209209
lsp.loan_application = loan_application_doc.name
@@ -227,7 +227,7 @@ def create_pledge(loan_application, loan=None):
227227
lsp.save()
228228
lsp.submit()
229229

230-
message = _("Loan Security Pledge Created : {0}").format(lsp.name)
230+
message = _("Loan Security Assignment Created : {0}").format(lsp.name)
231231
frappe.msgprint(message)
232232

233233
return lsp.name

lending/loan_management/doctype/loan_application/loan_application_dashboard.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ def get_data():
22
return {
33
"fieldname": "loan_application",
44
"transactions": [
5-
{"items": ["Loan", "Loan Security Pledge"]},
5+
{"items": ["Loan", "Loan Security Assignment"]},
66
],
77
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
{
2+
"actions": [],
3+
"allow_rename": 1,
4+
"creation": "2023-10-19 16:26:54.924575",
5+
"doctype": "DocType",
6+
"editable_grid": 1,
7+
"engine": "InnoDB",
8+
"field_order": [
9+
"loan",
10+
"loan_application",
11+
"loan_amount",
12+
"pending_principal_amount"
13+
],
14+
"fields": [
15+
{
16+
"fieldname": "loan",
17+
"fieldtype": "Link",
18+
"in_list_view": 1,
19+
"label": "Loan",
20+
"options": "Loan"
21+
},
22+
{
23+
"fieldname": "loan_application",
24+
"fieldtype": "Link",
25+
"label": "Loan Application",
26+
"options": "Loan Application"
27+
},
28+
{
29+
"fetch_from": "loan.loan_amount",
30+
"fieldname": "loan_amount",
31+
"fieldtype": "Currency",
32+
"label": "Loan Amount"
33+
},
34+
{
35+
"fieldname": "pending_principal_amount",
36+
"fieldtype": "Currency",
37+
"in_list_view": 1,
38+
"label": "Pending Principal Amount"
39+
}
40+
],
41+
"index_web_pages_for_search": 1,
42+
"istable": 1,
43+
"links": [],
44+
"modified": "2023-10-19 17:24:13.961740",
45+
"modified_by": "Administrator",
46+
"module": "Loan Management",
47+
"name": "Loan Assignment Detail",
48+
"owner": "Administrator",
49+
"permissions": [],
50+
"sort_field": "modified",
51+
"sort_order": "DESC",
52+
"states": []
53+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Copyright (c) 2023, Frappe Technologies Pvt. Ltd. and contributors
2+
# For license information, please see license.txt
3+
4+
# import frappe
5+
from frappe.model.document import Document
6+
7+
8+
class LoanAssignmentDetail(Document):
9+
pass

lending/loan_management/doctype/loan_disbursement/loan_disbursement.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from erpnext.accounts.general_ledger import make_gl_entries
1111
from erpnext.controllers.accounts_controller import AccountsController
1212

13-
from lending.loan_management.doctype.loan_security_unpledge.loan_security_unpledge import (
13+
from lending.loan_management.doctype.loan_security_release.loan_security_release import (
1414
get_pledged_security_qty,
1515
)
1616
from lending.loan_management.doctype.process_loan_interest_accrual.process_loan_interest_accrual import (
@@ -376,4 +376,6 @@ def get_disbursal_amount(loan, on_current_security_price=0):
376376

377377

378378
def get_maximum_amount_as_per_pledged_security(loan):
379-
return flt(frappe.db.get_value("Loan Security Pledge", {"loan": loan}, "sum(maximum_loan_value)"))
379+
return flt(
380+
frappe.db.get_value("Loan Security Assignment", {"loan": loan}, "sum(maximum_loan_value)")
381+
)

lending/loan_management/doctype/loan_repayment/loan_repayment.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1073,7 +1073,7 @@ def get_pending_principal_amount(loan):
10731073
)
10741074
else:
10751075
pending_principal_amount = (
1076-
flt(loan.disbursed_amount)
1076+
flt(loan.disbursed_amount or loan.loan_amount)
10771077
+ flt(loan.debit_adjustment_amount)
10781078
- flt(loan.credit_adjustment_amount)
10791079
- flt(loan.total_principal_paid)

lending/loan_management/doctype/loan_security/loan_security_dashboard.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ def get_data():
33
"fieldname": "loan_security",
44
"transactions": [
55
{"items": ["Loan Application", "Loan Security Price"]},
6-
{"items": ["Loan Security Pledge", "Loan Security Unpledge"]},
6+
{"items": ["Loan Security Assignment", "Loan Security Release"]},
77
],
88
}

lending/loan_management/doctype/loan_security_pledge/loan_security_pledge.js renamed to lending/loan_management/doctype/loan_security_assignment/loan_security_assignment.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) 2019, Frappe Technologies Pvt. Ltd. and contributors
22
// For license information, please see license.txt
33

4-
frappe.ui.form.on('Loan Security Pledge', {
4+
frappe.ui.form.on('Loan Security Assignment', {
55
calculate_amounts: function(frm, cdt, cdn) {
66
let row = locals[cdt][cdn];
77
frappe.model.set_value(cdt, cdn, 'amount', row.qty * row.loan_security_price);

0 commit comments

Comments
 (0)