Skip to content

Commit

Permalink
chore: fix fetch_if_empty for min_days_bw_disbursement_first_repayment (
Browse files Browse the repository at this point in the history
#98) (#99)

* chore: fix fetch_if_empty for min_days_bw_disbursement_first_repayment

* chore: min_days_bw_disbursement_first_repayment should be int

(cherry picked from commit 08becdd)

Co-authored-by: Anand Baburajan <[email protected]>
  • Loading branch information
mergify[bot] and anandbaburajan authored Oct 12, 2023
1 parent e9371c5 commit ab8d43c
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 4 deletions.
15 changes: 15 additions & 0 deletions lending/loan_management/doctype/loan/test_loan.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@

class TestLoan(unittest.TestCase):
def setUp(self):
set_loan_settings_in_company()
create_loan_accounts()
simple_terms_loans = [
["Personal Loan", 500000, 8.4, "Monthly as per repayment start date"],
Expand Down Expand Up @@ -1057,6 +1058,7 @@ def create_loan_product(
repayment_schedule_type=None,
repayment_date_on=None,
days_past_due_threshold_for_npa=None,
min_days_bw_disbursement_first_repayment=None,
):

if not frappe.db.exists("Loan Product", product_code):
Expand Down Expand Up @@ -1087,6 +1089,9 @@ def create_loan_product(
"repayment_periods": repayment_periods,
"write_off_amount": 100,
"days_past_due_threshold_for_npa": days_past_due_threshold_for_npa,
"min_days_bw_disbursement_first_repayment": min_days_bw_disbursement_first_repayment,
"min_auto_closure_tolerance_amount": -100,
"max_auto_closure_tolerance_amount": 100,
}
)

Expand All @@ -1097,6 +1102,8 @@ def create_loan_product(

loan_product.insert()

return loan_product


def create_loan_security_type():
if not frappe.db.exists("Loan Security Type", "Stock"):
Expand Down Expand Up @@ -1340,3 +1347,11 @@ def create_demand_loan(applicant, loan_product, loan_application, posting_date=N
loan.save()

return loan


def set_loan_settings_in_company(company=None):
if not company:
company = "_Test Company"
company = frappe.get_doc("Company", company)
company.min_days_bw_disbursement_first_repayment = 15
company.save()
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@
from lending.loan_management.doctype.loan.test_loan import (
create_loan_accounts,
create_loan_product,
set_loan_settings_in_company,
)


class TestLoanApplication(unittest.TestCase):
def setUp(self):
set_loan_settings_in_company()
create_loan_accounts()
create_loan_product(
"Home Loan",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
create_loan_security_type,
create_repayment_entry,
make_loan_disbursement_entry,
set_loan_settings_in_company,
)
from lending.loan_management.doctype.loan_application.loan_application import create_pledge
from lending.loan_management.doctype.loan_interest_accrual.loan_interest_accrual import (
Expand All @@ -42,6 +43,8 @@

class TestLoanDisbursement(unittest.TestCase):
def setUp(self):
set_loan_settings_in_company()

create_loan_accounts()

create_loan_product(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
create_loan_security_price,
create_loan_security_type,
make_loan_disbursement_entry,
set_loan_settings_in_company,
)
from lending.loan_management.doctype.loan_application.loan_application import create_pledge
from lending.loan_management.doctype.loan_interest_accrual.loan_interest_accrual import (
Expand All @@ -31,6 +32,8 @@

class TestLoanInterestAccrual(unittest.TestCase):
def setUp(self):
set_loan_settings_in_company()

create_loan_accounts()

create_loan_product(
Expand Down
4 changes: 4 additions & 0 deletions lending/loan_management/doctype/loan_product/loan_product.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
// For license information, please see license.txt

frappe.ui.form.on('Loan Product', {
setup(frm) {
frm.add_fetch("company", "min_days_bw_disbursement_first_repayment", "min_days_bw_disbursement_first_repayment");
},

onload: function(frm) {
$.each(["penalty_income_account", "interest_income_account"], function (i, field) {
frm.set_query(field, function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -380,17 +380,16 @@
"reqd": 1
},
{
"fetch_from": "company.min_days_bw_disbursement_first_repayment",
"fetch_if_empty": 1,
"fieldname": "min_days_bw_disbursement_first_repayment",
"fieldtype": "Int",
"label": "Minimum days between Disbursement date and first Repayment date",
"non_negative": 1
"non_negative": 1,
"reqd": 1
}
],
"index_web_pages_for_search": 1,
"links": [],
"modified": "2023-10-12 12:12:02.553449",
"modified": "2023-10-12 13:35:48.346212",
"modified_by": "Administrator",
"module": "Loan Management",
"name": "Loan Product",
Expand Down
13 changes: 13 additions & 0 deletions lending/loan_management/doctype/loan_product/loan_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,23 @@


class LoanProduct(Document):
def before_validate(self):
self.set_missing_values()

def validate(self):
self.validate_accounts()
self.validate_rates()

def set_missing_values(self):
company_min_days_bw_disbursement_first_repayment = frappe.get_cached_value(
"Company", self.company, "min_days_bw_disbursement_first_repayment"
)
if (
self.min_days_bw_disbursement_first_repayment is None
and company_min_days_bw_disbursement_first_repayment
):
self.min_days_bw_disbursement_first_repayment = company_min_days_bw_disbursement_first_repayment

def validate_accounts(self):
for fieldname in [
"payment_account",
Expand Down

0 comments on commit ab8d43c

Please sign in to comment.