Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: closed status in loan disbursement #222

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"disbursement_references_section",
"reference_date",
"days_past_due",
"status",
"column_break_17",
"reference_number",
"amended_from"
Expand Down Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
@@ -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];
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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];
},
Expand Down
1 change: 1 addition & 0 deletions lending/patches.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
35 changes: 35 additions & 0 deletions lending/patches/v15_0/loan_disbursement_status_patch.py
Original file line number Diff line number Diff line change
@@ -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'
"""
)
Loading