diff --git a/lending/loan_management/doctype/loan_disbursement/loan_disbursement.json b/lending/loan_management/doctype/loan_disbursement/loan_disbursement.json index 3007f627..af9ca75c 100644 --- a/lending/loan_management/doctype/loan_disbursement/loan_disbursement.json +++ b/lending/loan_management/doctype/loan_disbursement/loan_disbursement.json @@ -46,6 +46,7 @@ "disbursement_references_section", "reference_date", "days_past_due", + "status", "column_break_17", "reference_number", "amended_from" @@ -343,12 +344,22 @@ "fieldtype": "Currency", "label": "Principal Amount Paid", "options": "Company:company:default_currency" + }, + { + "default": "Draft", + "fieldname": "status", + "fieldtype": "Select", + "in_list_view": 1, + "in_standard_filter": 1, + "label": "Status", + "options": "\nDraft\nSubmitted\nCancelled\nClosed", + "read_only": 1 } ], "index_web_pages_for_search": 1, "is_submittable": 1, "links": [], - "modified": "2024-12-31 22:51:42.962589", + "modified": "2025-01-01 11:56:14.127955", "modified_by": "Administrator", "module": "Loan Management", "name": "Loan Disbursement", diff --git a/lending/loan_management/doctype/loan_disbursement/loan_disbursement.py b/lending/loan_management/doctype/loan_disbursement/loan_disbursement.py index 2ba2e63d..8a0d8d53 100644 --- a/lending/loan_management/doctype/loan_disbursement/loan_disbursement.py +++ b/lending/loan_management/doctype/loan_disbursement/loan_disbursement.py @@ -42,6 +42,7 @@ class LoanDisbursement(AccountsController): def validate(self): + self.set_status() self.set_missing_values() self.validate_disbursal_amount() if self.repayment_schedule_type == "Line of Credit": @@ -127,6 +128,14 @@ def on_submit(self): self.withheld_security_deposit() self.make_gl_entries() + def set_status(self): + if self.docstatus == 0: + self.status = "Draft" + elif self.docstatus == 1: + self.db_set("status", "Submitted") + elif self.docstatus == 2: + self.db_set("status", "Cancelled") + def add_bpi_difference_entry(self, gle_map): if flt(self.bpi_amount_difference) > 0: broken_period_interest_account = frappe.db.get_value( @@ -247,6 +256,7 @@ def on_cancel(self): self.make_gl_entries(cancel=1) self.ignore_linked_doctypes = ["GL Entry", "Payment Ledger Entry"] + self.set_status() def set_missing_values(self): if not self.disbursement_date: diff --git a/lending/loan_management/doctype/loan_disbursement/loan_disbursement_list.js b/lending/loan_management/doctype/loan_disbursement/loan_disbursement_list.js new file mode 100644 index 00000000..a54af865 --- /dev/null +++ b/lending/loan_management/doctype/loan_disbursement/loan_disbursement_list.js @@ -0,0 +1,14 @@ +// Copyright (c) 2024, Frappe Technologies Pvt. Ltd. and Contributors +// License: GNU General Public License v3. See license.txt + +frappe.listview_settings['Loan Disbursement'] = { + get_indicator: function(doc) { + var status_color = { + "Draft": "red", + "Submitted": "blue", + "Cancelled": "red", + "Closed": "green" + }; + return [__(doc.status), status_color[doc.status], "status,=,"+doc.status]; + }, +}; diff --git a/lending/loan_management/doctype/loan_repayment/loan_repayment.py b/lending/loan_management/doctype/loan_repayment/loan_repayment.py index b7160728..e3f5bbb9 100644 --- a/lending/loan_management/doctype/loan_repayment/loan_repayment.py +++ b/lending/loan_management/doctype/loan_repayment/loan_repayment.py @@ -840,6 +840,10 @@ def update_repayment_schedule_status(self, cancel=0): if self.loan_disbursement: filters["loan_disbursement"] = self.loan_disbursement + if cancel: + frappe.db.set_value("Loan Disbursement", self.loan_disbursement, "status", "Submitted") + if status == "Closed": + frappe.db.set_value("Loan Disbursement", self.loan_disbursement, "status", status) repayment_schedule = frappe.get_value("Loan Repayment Schedule", filters, "name") if repayment_schedule: @@ -921,6 +925,9 @@ def mark_as_unpaid(self): query = query.set(loan.status, "Disbursed") self.update_repayment_schedule_status(cancel=1) + if self.repayment_schedule_type == "Line of Credit" and self.loan_disbursement: + self.update_repayment_schedule_status(cancel=1) + if flt(self.excess_amount) > 0: query = query.set(loan.excess_amount_paid, loan.excess_amount_paid - self.excess_amount) diff --git a/lending/loan_management/doctype/loan_repayment_schedule/loan_repayment_schedule_list.js b/lending/loan_management/doctype/loan_repayment_schedule/loan_repayment_schedule_list.js index 2f098f4b..47c6bcb5 100644 --- a/lending/loan_management/doctype/loan_repayment_schedule/loan_repayment_schedule_list.js +++ b/lending/loan_management/doctype/loan_repayment_schedule/loan_repayment_schedule_list.js @@ -7,6 +7,7 @@ frappe.listview_settings['Loan Repayment Schedule'] = { "Draft": "red", "Active": "green", "Restructured": "orange", + "Closed": "green" }; return [__(doc.status), status_color[doc.status], "status,=,"+doc.status]; }, diff --git a/lending/patches.txt b/lending/patches.txt index 7ff7260b..face0e40 100644 --- a/lending/patches.txt +++ b/lending/patches.txt @@ -36,3 +36,4 @@ lending.patches.v15_0.update_loan_product_accounts lending.patches.v15_0.create_accounting_dimensions_for_loan_doctypes lending.patches.v15_0.update_maturity_date lending.patches.v15_0.loan_repayment_schedule_status_patch +lending.patches.v15_0.loan_disbursement_status_patch diff --git a/lending/patches/v15_0/loan_disbursement_status_patch.py b/lending/patches/v15_0/loan_disbursement_status_patch.py new file mode 100644 index 00000000..e540e8ce --- /dev/null +++ b/lending/patches/v15_0/loan_disbursement_status_patch.py @@ -0,0 +1,35 @@ +import frappe + +frappe.db.sql( + """ + UPDATE `tabLoan Disbursement` + SET status = 'Draft' + WHERE docstatus = 0 +""" +) + +frappe.db.sql( + """ + UPDATE `tabLoan Disbursement` + SET status = 'Submitted' + WHERE docstatus = 1 +""" +) + +frappe.db.sql( + """ + UPDATE `tabLoan Disbursement` + SET status = 'Cancelled' + WHERE docstatus = 2 +""" +) + +frappe.db.sql( + """ + UPDATE `tabLoan Disbursement` ld + INNER JOIN `tabLoan Repayment Schedule` lrs + ON ld.name = lrs.loan_disbursement + SET ld.status = 'Closed' + WHERE lrs.status = 'Closed' +""" +)