Merge pull request #26252 from deepeshgarg007/loan_security_pledge_on_cancel

fix: Cancellation of Loan Security Pledges
This commit is contained in:
Deepesh Garg 2021-06-29 20:23:46 +05:30 committed by GitHub
commit a287b22b55
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 76 additions and 26 deletions

View File

@ -35,7 +35,9 @@
"no_copy": 1, "no_copy": 1,
"options": "Loan Security Pledge", "options": "Loan Security Pledge",
"print_hide": 1, "print_hide": 1,
"read_only": 1 "read_only": 1,
"show_days": 1,
"show_seconds": 1
}, },
{ {
"fetch_from": "loan_application.applicant", "fetch_from": "loan_application.applicant",
@ -45,47 +47,63 @@
"in_standard_filter": 1, "in_standard_filter": 1,
"label": "Applicant", "label": "Applicant",
"options": "applicant_type", "options": "applicant_type",
"reqd": 1 "reqd": 1,
"show_days": 1,
"show_seconds": 1
}, },
{ {
"fieldname": "loan_security_details_section", "fieldname": "loan_security_details_section",
"fieldtype": "Section Break", "fieldtype": "Section Break",
"label": "Loan Security Details" "label": "Loan Security Details",
"show_days": 1,
"show_seconds": 1
}, },
{ {
"fieldname": "column_break_3", "fieldname": "column_break_3",
"fieldtype": "Column Break" "fieldtype": "Column Break",
"show_days": 1,
"show_seconds": 1
}, },
{ {
"fieldname": "loan", "fieldname": "loan",
"fieldtype": "Link", "fieldtype": "Link",
"label": "Loan", "label": "Loan",
"options": "Loan" "options": "Loan",
"show_days": 1,
"show_seconds": 1
}, },
{ {
"fieldname": "loan_application", "fieldname": "loan_application",
"fieldtype": "Link", "fieldtype": "Link",
"label": "Loan Application", "label": "Loan Application",
"options": "Loan Application" "options": "Loan Application",
"show_days": 1,
"show_seconds": 1
}, },
{ {
"fieldname": "total_security_value", "fieldname": "total_security_value",
"fieldtype": "Currency", "fieldtype": "Currency",
"label": "Total Security Value", "label": "Total Security Value",
"options": "Company:company:default_currency", "options": "Company:company:default_currency",
"read_only": 1 "read_only": 1,
"show_days": 1,
"show_seconds": 1
}, },
{ {
"fieldname": "maximum_loan_value", "fieldname": "maximum_loan_value",
"fieldtype": "Currency", "fieldtype": "Currency",
"label": "Maximum Loan Value", "label": "Maximum Loan Value",
"options": "Company:company:default_currency", "options": "Company:company:default_currency",
"read_only": 1 "read_only": 1,
"show_days": 1,
"show_seconds": 1
}, },
{ {
"fieldname": "loan_details_section", "fieldname": "loan_details_section",
"fieldtype": "Section Break", "fieldtype": "Section Break",
"label": "Loan Details" "label": "Loan Details",
"show_days": 1,
"show_seconds": 1
}, },
{ {
"default": "Requested", "default": "Requested",
@ -94,37 +112,49 @@
"in_list_view": 1, "in_list_view": 1,
"in_standard_filter": 1, "in_standard_filter": 1,
"label": "Status", "label": "Status",
"options": "Requested\nUnpledged\nPledged\nPartially Pledged", "options": "Requested\nUnpledged\nPledged\nPartially Pledged\nCancelled",
"read_only": 1 "read_only": 1,
"show_days": 1,
"show_seconds": 1
}, },
{ {
"fieldname": "pledge_time", "fieldname": "pledge_time",
"fieldtype": "Datetime", "fieldtype": "Datetime",
"label": "Pledge Time", "label": "Pledge Time",
"read_only": 1 "read_only": 1,
"show_days": 1,
"show_seconds": 1
}, },
{ {
"fieldname": "securities", "fieldname": "securities",
"fieldtype": "Table", "fieldtype": "Table",
"label": "Securities", "label": "Securities",
"options": "Pledge", "options": "Pledge",
"reqd": 1 "reqd": 1,
"show_days": 1,
"show_seconds": 1
}, },
{ {
"fieldname": "column_break_11", "fieldname": "column_break_11",
"fieldtype": "Column Break" "fieldtype": "Column Break",
"show_days": 1,
"show_seconds": 1
}, },
{ {
"fieldname": "section_break_10", "fieldname": "section_break_10",
"fieldtype": "Section Break", "fieldtype": "Section Break",
"label": "Totals" "label": "Totals",
"show_days": 1,
"show_seconds": 1
}, },
{ {
"fieldname": "company", "fieldname": "company",
"fieldtype": "Link", "fieldtype": "Link",
"label": "Company", "label": "Company",
"options": "Company", "options": "Company",
"reqd": 1 "reqd": 1,
"show_days": 1,
"show_seconds": 1
}, },
{ {
"fetch_from": "loan.applicant_type", "fetch_from": "loan.applicant_type",
@ -132,35 +162,45 @@
"fieldtype": "Select", "fieldtype": "Select",
"label": "Applicant Type", "label": "Applicant Type",
"options": "Employee\nMember\nCustomer", "options": "Employee\nMember\nCustomer",
"reqd": 1 "reqd": 1,
"show_days": 1,
"show_seconds": 1
}, },
{ {
"collapsible": 1, "collapsible": 1,
"fieldname": "more_information_section", "fieldname": "more_information_section",
"fieldtype": "Section Break", "fieldtype": "Section Break",
"label": "More Information" "label": "More Information",
"show_days": 1,
"show_seconds": 1
}, },
{ {
"allow_on_submit": 1, "allow_on_submit": 1,
"fieldname": "reference_no", "fieldname": "reference_no",
"fieldtype": "Data", "fieldtype": "Data",
"label": "Reference No" "label": "Reference No",
"show_days": 1,
"show_seconds": 1
}, },
{ {
"fieldname": "column_break_18", "fieldname": "column_break_18",
"fieldtype": "Column Break" "fieldtype": "Column Break",
"show_days": 1,
"show_seconds": 1
}, },
{ {
"allow_on_submit": 1, "allow_on_submit": 1,
"fieldname": "description", "fieldname": "description",
"fieldtype": "Text", "fieldtype": "Text",
"label": "Description" "label": "Description",
"show_days": 1,
"show_seconds": 1
} }
], ],
"index_web_pages_for_search": 1, "index_web_pages_for_search": 1,
"is_submittable": 1, "is_submittable": 1,
"links": [], "links": [],
"modified": "2021-04-19 18:23:16.953305", "modified": "2021-06-29 17:15:16.082256",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "Loan Management", "module": "Loan Management",
"name": "Loan Security Pledge", "name": "Loan Security Pledge",

View File

@ -23,6 +23,12 @@ class LoanSecurityPledge(Document):
update_shortfall_status(self.loan, self.total_security_value) update_shortfall_status(self.loan, self.total_security_value)
update_loan(self.loan, self.maximum_loan_value) update_loan(self.loan, self.maximum_loan_value)
def on_cancel(self):
if self.loan:
self.db_set("status", "Cancelled")
self.db_set("pledge_time", None)
update_loan(self.loan, self.maximum_loan_value, cancel=1)
def validate_duplicate_securities(self): def validate_duplicate_securities(self):
security_list = [] security_list = []
for security in self.securities: for security in self.securities:
@ -36,7 +42,7 @@ class LoanSecurityPledge(Document):
existing_pledge = '' existing_pledge = ''
if self.loan: if self.loan:
existing_pledge = frappe.db.get_value('Loan Security Pledge', {'loan': self.loan}, ['name']) existing_pledge = frappe.db.get_value('Loan Security Pledge', {'loan': self.loan, 'docstatus': 1}, ['name'])
if existing_pledge: if existing_pledge:
loan_security_type = frappe.db.get_value('Pledge', {'parent': existing_pledge}, ['loan_security_type']) loan_security_type = frappe.db.get_value('Pledge', {'parent': existing_pledge}, ['loan_security_type'])
@ -77,8 +83,12 @@ class LoanSecurityPledge(Document):
self.total_security_value = total_security_value self.total_security_value = total_security_value
self.maximum_loan_value = maximum_loan_value self.maximum_loan_value = maximum_loan_value
def update_loan(loan, maximum_value_against_pledge): def update_loan(loan, maximum_value_against_pledge, cancel=0):
maximum_loan_value = frappe.db.get_value('Loan', {'name': loan}, ['maximum_loan_amount']) maximum_loan_value = frappe.db.get_value('Loan', {'name': loan}, ['maximum_loan_amount'])
frappe.db.sql(""" UPDATE `tabLoan` SET maximum_loan_amount=%s, is_secured_loan=1 if cancel:
WHERE name=%s""", (maximum_loan_value + maximum_value_against_pledge, loan)) frappe.db.sql(""" UPDATE `tabLoan` SET maximum_loan_amount=%s
WHERE name=%s""", (maximum_loan_value - maximum_value_against_pledge, loan))
else:
frappe.db.sql(""" UPDATE `tabLoan` SET maximum_loan_amount=%s, is_secured_loan=1
WHERE name=%s""", (maximum_loan_value + maximum_value_against_pledge, loan))