Skip to content

Commit

Permalink
Merge pull request #109 from frappe/mergify/copy/poc-staging/pr-108
Browse files Browse the repository at this point in the history
feat: Assign multiple securities to one loan (#108)
  • Loading branch information
deepeshgarg007 committed Oct 20, 2023
2 parents 8701c6a + 4db813e commit 1f4884e
Show file tree
Hide file tree
Showing 31 changed files with 214 additions and 137 deletions.
6 changes: 3 additions & 3 deletions lending/loan_management/doctype/loan/loan.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ frappe.ui.form.on('Loan', {
setup: function(frm) {
frm.make_methods = {
'Loan Disbursement': function() { frm.trigger('make_loan_disbursement') },
'Loan Security Unpledge': function() { frm.trigger('create_loan_security_unpledge') },
'Loan Security Release': function() { frm.trigger('create_loan_security_unpledge') },
'Loan Write Off': function() { frm.trigger('make_loan_write_off_entry') }
}
},
onload: function (frm) {
// Ignore loan security pledge on cancel of loan
frm.ignore_doctypes_on_cancel_all = ["Loan Security Pledge", "Loan Repayment Schedule"];
frm.ignore_doctypes_on_cancel_all = ["Loan Security Assignment", "Loan Repayment Schedule"];

frm.set_query("loan_application", function () {
return {
Expand Down Expand Up @@ -82,7 +82,7 @@ frappe.ui.form.on('Loan', {
}

if (frm.doc.status == "Loan Closure Requested") {
frm.add_custom_button(__('Loan Security Unpledge'), function() {
frm.add_custom_button(__('Loan Security Release'), function() {
frm.trigger("create_loan_security_unpledge");
},__('Create'));
}
Expand Down
12 changes: 7 additions & 5 deletions lending/loan_management/doctype/loan/loan.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from erpnext.accounts.doctype.journal_entry.journal_entry import get_payment_entry
from erpnext.controllers.accounts_controller import AccountsController

from lending.loan_management.doctype.loan_security_unpledge.loan_security_unpledge import (
from lending.loan_management.doctype.loan_security_release.loan_security_release import (
get_pledged_security_qty,
)

Expand Down Expand Up @@ -244,7 +244,7 @@ def validate_loan_amount(self):
def link_loan_security_pledge(self):
if self.is_secured_loan and self.loan_application:
maximum_loan_value = frappe.db.get_value(
"Loan Security Pledge",
"Loan Security Assignment",
{"loan_application": self.loan_application, "status": "Requested"},
"sum(maximum_loan_value)",
)
Expand Down Expand Up @@ -272,7 +272,9 @@ def accrue_loan_interest(self):
)

def unlink_loan_security_pledge(self):
pledges = frappe.get_all("Loan Security Pledge", fields=["name"], filters={"loan": self.name})
pledges = frappe.get_all(
"Loan Security Assignment", fields=["name"], filters={"loan": self.name}
)
pledge_list = [d.name for d in pledges]
if pledge_list:
frappe.db.sql(
Expand Down Expand Up @@ -513,7 +515,7 @@ def unpledge_security(
# will unpledge qty based on loan security pledge
elif loan_security_pledge:
security_map = {}
pledge_doc = frappe.get_doc("Loan Security Pledge", loan_security_pledge)
pledge_doc = frappe.get_doc("Loan Security Assignment", loan_security_pledge)
for security in pledge_doc.securities:
security_map.setdefault(security.loan_security, security.qty)

Expand Down Expand Up @@ -545,7 +547,7 @@ def unpledge_security(


def create_loan_security_unpledge(unpledge_map, loan, company, applicant_type, applicant):
unpledge_request = frappe.new_doc("Loan Security Unpledge")
unpledge_request = frappe.new_doc("Loan Security Release")
unpledge_request.applicant_type = applicant_type
unpledge_request.applicant = applicant
unpledge_request.loan = loan
Expand Down
4 changes: 2 additions & 2 deletions lending/loan_management/doctype/loan/loan_dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ def get_data():
{
"items": [
"Loan Repayment Schedule",
"Loan Security Pledge",
"Loan Security Assignment",
"Loan Security Shortfall",
"Loan Disbursement",
]
},
{"items": ["Loan Repayment", "Loan Interest Accrual", "Loan Write Off", "Loan Restructure"]},
{"items": ["Loan Security Unpledge", "Days Past Due Log", "Journal Entry", "Sales Invoice"]},
{"items": ["Loan Security Release", "Days Past Due Log", "Journal Entry", "Sales Invoice"]},
],
}
4 changes: 2 additions & 2 deletions lending/loan_management/doctype/loan/test_loan.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
days_in_year,
)
from lending.loan_management.doctype.loan_repayment.loan_repayment import calculate_amounts
from lending.loan_management.doctype.loan_security_unpledge.loan_security_unpledge import (
from lending.loan_management.doctype.loan_security_release.loan_security_release import (
get_pledged_security_qty,
)
from lending.loan_management.doctype.process_loan_interest_accrual.process_loan_interest_accrual import (
Expand Down Expand Up @@ -1146,7 +1146,7 @@ def create_loan_security():

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

lsp = frappe.new_doc("Loan Security Pledge")
lsp = frappe.new_doc("Loan Security Assignment")
lsp.applicant_type = "Customer"
lsp.applicant = applicant
lsp.company = "_Test Company"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ frappe.ui.form.on('Loan Application', {
setup: function(frm) {
frm.make_methods = {
'Loan': function() { frm.trigger('create_loan') },
'Loan Security Pledge': function() { frm.trigger('create_loan_security_pledge') },
'Loan Security Assignment': function() { frm.trigger('create_loan_security_pledge') },
}
},
refresh: function(frm) {
Expand Down Expand Up @@ -39,9 +39,9 @@ frappe.ui.form.on('Loan Application', {
if (frm.doc.status == "Approved") {

if (frm.doc.is_secured_loan) {
frappe.db.get_value("Loan Security Pledge", {"loan_application": frm.doc.name, "docstatus": 1}, "name", (r) => {
frappe.db.get_value("Loan Security Assignment", {"loan_application": frm.doc.name, "docstatus": 1}, "name", (r) => {
if (Object.keys(r).length === 0) {
frm.add_custom_button(__('Loan Security Pledge'), function() {
frm.add_custom_button(__('Loan Security Assignment'), function() {
frm.trigger('create_loan_security_pledge');
},__('Create'))
}
Expand Down Expand Up @@ -72,7 +72,7 @@ frappe.ui.form.on('Loan Application', {
create_loan_security_pledge: function(frm) {

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

frappe.call({
Expand All @@ -81,7 +81,7 @@ frappe.ui.form.on('Loan Application', {
loan_application: frm.doc.name
},
callback: function(r) {
frappe.set_route("Form", "Loan Security Pledge", r.message);
frappe.set_route("Form", "Loan Security Assignment", r.message);
}
})
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ def update_accounts(source_doc, target_doc, source_parent):
def create_pledge(loan_application, loan=None):
loan_application_doc = frappe.get_doc("Loan Application", loan_application)

lsp = frappe.new_doc("Loan Security Pledge")
lsp = frappe.new_doc("Loan Security Assignment")
lsp.applicant_type = loan_application_doc.applicant_type
lsp.applicant = loan_application_doc.applicant
lsp.loan_application = loan_application_doc.name
Expand All @@ -227,7 +227,7 @@ def create_pledge(loan_application, loan=None):
lsp.save()
lsp.submit()

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

return lsp.name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ def get_data():
return {
"fieldname": "loan_application",
"transactions": [
{"items": ["Loan", "Loan Security Pledge"]},
{"items": ["Loan", "Loan Security Assignment"]},
],
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
"actions": [],
"allow_rename": 1,
"creation": "2023-10-19 16:26:54.924575",
"doctype": "DocType",
"editable_grid": 1,
"engine": "InnoDB",
"field_order": [
"loan",
"loan_application",
"loan_amount",
"pending_principal_amount"
],
"fields": [
{
"fieldname": "loan",
"fieldtype": "Link",
"in_list_view": 1,
"label": "Loan",
"options": "Loan"
},
{
"fieldname": "loan_application",
"fieldtype": "Link",
"label": "Loan Application",
"options": "Loan Application"
},
{
"fetch_from": "loan.loan_amount",
"fieldname": "loan_amount",
"fieldtype": "Currency",
"label": "Loan Amount"
},
{
"fieldname": "pending_principal_amount",
"fieldtype": "Currency",
"in_list_view": 1,
"label": "Pending Principal Amount"
}
],
"index_web_pages_for_search": 1,
"istable": 1,
"links": [],
"modified": "2023-10-19 17:24:13.961740",
"modified_by": "Administrator",
"module": "Loan Management",
"name": "Loan Assignment Detail",
"owner": "Administrator",
"permissions": [],
"sort_field": "modified",
"sort_order": "DESC",
"states": []
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Copyright (c) 2023, Frappe Technologies Pvt. Ltd. and contributors
# For license information, please see license.txt

# import frappe
from frappe.model.document import Document


class LoanAssignmentDetail(Document):
pass
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from erpnext.accounts.general_ledger import make_gl_entries
from erpnext.controllers.accounts_controller import AccountsController

from lending.loan_management.doctype.loan_security_unpledge.loan_security_unpledge import (
from lending.loan_management.doctype.loan_security_release.loan_security_release import (
get_pledged_security_qty,
)
from lending.loan_management.doctype.process_loan_interest_accrual.process_loan_interest_accrual import (
Expand Down Expand Up @@ -376,4 +376,6 @@ def get_disbursal_amount(loan, on_current_security_price=0):


def get_maximum_amount_as_per_pledged_security(loan):
return flt(frappe.db.get_value("Loan Security Pledge", {"loan": loan}, "sum(maximum_loan_value)"))
return flt(
frappe.db.get_value("Loan Security Assignment", {"loan": loan}, "sum(maximum_loan_value)")
)
Original file line number Diff line number Diff line change
Expand Up @@ -1073,7 +1073,7 @@ def get_pending_principal_amount(loan):
)
else:
pending_principal_amount = (
flt(loan.disbursed_amount)
flt(loan.disbursed_amount or loan.loan_amount)
+ flt(loan.debit_adjustment_amount)
- flt(loan.credit_adjustment_amount)
- flt(loan.total_principal_paid)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ def get_data():
"fieldname": "loan_security",
"transactions": [
{"items": ["Loan Application", "Loan Security Price"]},
{"items": ["Loan Security Pledge", "Loan Security Unpledge"]},
{"items": ["Loan Security Assignment", "Loan Security Release"]},
],
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) 2019, Frappe Technologies Pvt. Ltd. and contributors
// For license information, please see license.txt

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

0 comments on commit 1f4884e

Please sign in to comment.