Merge branch 'develop' into refactor/stock/remaining-reports
This commit is contained in:
commit
334b158f0b
@ -214,6 +214,7 @@
|
|||||||
"reqd": 1
|
"reqd": 1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"default": "1",
|
||||||
"depends_on": "eval:doc.uom != doc.stock_uom",
|
"depends_on": "eval:doc.uom != doc.stock_uom",
|
||||||
"fieldname": "conversion_factor",
|
"fieldname": "conversion_factor",
|
||||||
"fieldtype": "Float",
|
"fieldtype": "Float",
|
||||||
@ -820,6 +821,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"collapsible": 1,
|
"collapsible": 1,
|
||||||
|
"collapsible_depends_on": "eval: doc.margin_type || doc.discount_amount",
|
||||||
"fieldname": "section_break_26",
|
"fieldname": "section_break_26",
|
||||||
"fieldtype": "Section Break",
|
"fieldtype": "Section Break",
|
||||||
"label": "Discount and Margin"
|
"label": "Discount and Margin"
|
||||||
@ -871,7 +873,7 @@
|
|||||||
"idx": 1,
|
"idx": 1,
|
||||||
"istable": 1,
|
"istable": 1,
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2022-10-12 03:37:29.032732",
|
"modified": "2022-10-26 16:05:37.304788",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Accounts",
|
"module": "Accounts",
|
||||||
"name": "Purchase Invoice Item",
|
"name": "Purchase Invoice Item",
|
||||||
|
|||||||
@ -247,6 +247,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"collapsible": 1,
|
"collapsible": 1,
|
||||||
|
"collapsible_depends_on": "eval: doc.margin_type || doc.discount_amount",
|
||||||
"fieldname": "discount_and_margin",
|
"fieldname": "discount_and_margin",
|
||||||
"fieldtype": "Section Break",
|
"fieldtype": "Section Break",
|
||||||
"label": "Discount and Margin"
|
"label": "Discount and Margin"
|
||||||
@ -876,7 +877,7 @@
|
|||||||
"idx": 1,
|
"idx": 1,
|
||||||
"istable": 1,
|
"istable": 1,
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2022-10-10 20:57:38.340026",
|
"modified": "2022-10-26 11:38:36.119339",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Accounts",
|
"module": "Accounts",
|
||||||
"name": "Sales Invoice Item",
|
"name": "Sales Invoice Item",
|
||||||
|
|||||||
@ -51,6 +51,8 @@ frappe.query_reports["Accounts Payable"] = {
|
|||||||
} else {
|
} else {
|
||||||
frappe.query_report.set_filter_value('tax_id', "");
|
frappe.query_report.set_filter_value('tax_id', "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
frappe.query_report.refresh();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@ -748,7 +748,7 @@ class ReceivablePayableReport(object):
|
|||||||
|
|
||||||
self.add_accounting_dimensions_filters()
|
self.add_accounting_dimensions_filters()
|
||||||
|
|
||||||
def get_cost_center_conditions(self, conditions):
|
def get_cost_center_conditions(self):
|
||||||
lft, rgt = frappe.db.get_value("Cost Center", self.filters.cost_center, ["lft", "rgt"])
|
lft, rgt = frappe.db.get_value("Cost Center", self.filters.cost_center, ["lft", "rgt"])
|
||||||
cost_center_list = [
|
cost_center_list = [
|
||||||
center.name
|
center.name
|
||||||
|
|||||||
@ -777,6 +777,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"collapsible": 1,
|
"collapsible": 1,
|
||||||
|
"collapsible_depends_on": "eval: doc.margin_type || doc.discount_amount",
|
||||||
"fieldname": "discount_and_margin_section",
|
"fieldname": "discount_and_margin_section",
|
||||||
"fieldtype": "Section Break",
|
"fieldtype": "Section Break",
|
||||||
"label": "Discount and Margin"
|
"label": "Discount and Margin"
|
||||||
@ -894,7 +895,7 @@
|
|||||||
"index_web_pages_for_search": 1,
|
"index_web_pages_for_search": 1,
|
||||||
"istable": 1,
|
"istable": 1,
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2022-09-07 11:12:38.634976",
|
"modified": "2022-10-26 16:47:41.364387",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Buying",
|
"module": "Buying",
|
||||||
"name": "Purchase Order Item",
|
"name": "Purchase Order Item",
|
||||||
|
|||||||
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
|
|
||||||
import frappe
|
import frappe
|
||||||
|
from frappe.custom.doctype.property_setter.property_setter import make_property_setter
|
||||||
from frappe.test_runner import make_test_records
|
from frappe.test_runner import make_test_records
|
||||||
|
|
||||||
from erpnext.accounts.party import get_due_date
|
from erpnext.accounts.party import get_due_date
|
||||||
@ -152,6 +153,40 @@ class TestSupplier(FrappeTestCase):
|
|||||||
# Rollback
|
# Rollback
|
||||||
address.delete()
|
address.delete()
|
||||||
|
|
||||||
|
def test_serach_fields_for_supplier(self):
|
||||||
|
from erpnext.controllers.queries import supplier_query
|
||||||
|
|
||||||
|
supplier_name = create_supplier(supplier_name="Test Supplier 1").name
|
||||||
|
|
||||||
|
make_property_setter(
|
||||||
|
"Supplier", None, "search_fields", "supplier_group", "Data", for_doctype="Doctype"
|
||||||
|
)
|
||||||
|
|
||||||
|
data = supplier_query(
|
||||||
|
"Supplier", supplier_name, "name", 0, 20, filters={"name": supplier_name}, as_dict=True
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertEqual(data[0].name, supplier_name)
|
||||||
|
self.assertEqual(data[0].supplier_group, "Services")
|
||||||
|
self.assertTrue("supplier_type" not in data[0])
|
||||||
|
|
||||||
|
make_property_setter(
|
||||||
|
"Supplier",
|
||||||
|
None,
|
||||||
|
"search_fields",
|
||||||
|
"supplier_group, supplier_type",
|
||||||
|
"Data",
|
||||||
|
for_doctype="Doctype",
|
||||||
|
)
|
||||||
|
data = supplier_query(
|
||||||
|
"Supplier", supplier_name, "name", 0, 20, filters={"name": supplier_name}, as_dict=True
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertEqual(data[0].name, supplier_name)
|
||||||
|
self.assertEqual(data[0].supplier_group, "Services")
|
||||||
|
self.assertEqual(data[0].supplier_type, "Company")
|
||||||
|
self.assertTrue("supplier_type" in data[0])
|
||||||
|
|
||||||
|
|
||||||
def create_supplier(**args):
|
def create_supplier(**args):
|
||||||
args = frappe._dict(args)
|
args = frappe._dict(args)
|
||||||
|
|||||||
@ -78,18 +78,16 @@ def lead_query(doctype, txt, searchfield, start, page_len, filters):
|
|||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
@frappe.validate_and_sanitize_search_inputs
|
@frappe.validate_and_sanitize_search_inputs
|
||||||
def customer_query(doctype, txt, searchfield, start, page_len, filters):
|
def customer_query(doctype, txt, searchfield, start, page_len, filters, as_dict=False):
|
||||||
doctype = "Customer"
|
doctype = "Customer"
|
||||||
conditions = []
|
conditions = []
|
||||||
cust_master_name = frappe.defaults.get_user_default("cust_master_name")
|
cust_master_name = frappe.defaults.get_user_default("cust_master_name")
|
||||||
|
|
||||||
if cust_master_name == "Customer Name":
|
fields = ["name"]
|
||||||
fields = ["name", "customer_group", "territory"]
|
if cust_master_name != "Customer Name":
|
||||||
else:
|
fields = ["customer_name"]
|
||||||
fields = ["name", "customer_name", "customer_group", "territory"]
|
|
||||||
|
|
||||||
fields = get_fields(doctype, fields)
|
fields = get_fields(doctype, fields)
|
||||||
|
|
||||||
searchfields = frappe.get_meta(doctype).get_search_fields()
|
searchfields = frappe.get_meta(doctype).get_search_fields()
|
||||||
searchfields = " or ".join(field + " like %(txt)s" for field in searchfields)
|
searchfields = " or ".join(field + " like %(txt)s" for field in searchfields)
|
||||||
|
|
||||||
@ -112,20 +110,20 @@ def customer_query(doctype, txt, searchfield, start, page_len, filters):
|
|||||||
}
|
}
|
||||||
),
|
),
|
||||||
{"txt": "%%%s%%" % txt, "_txt": txt.replace("%", ""), "start": start, "page_len": page_len},
|
{"txt": "%%%s%%" % txt, "_txt": txt.replace("%", ""), "start": start, "page_len": page_len},
|
||||||
|
as_dict=as_dict,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
# searches for supplier
|
# searches for supplier
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
@frappe.validate_and_sanitize_search_inputs
|
@frappe.validate_and_sanitize_search_inputs
|
||||||
def supplier_query(doctype, txt, searchfield, start, page_len, filters):
|
def supplier_query(doctype, txt, searchfield, start, page_len, filters, as_dict=False):
|
||||||
doctype = "Supplier"
|
doctype = "Supplier"
|
||||||
supp_master_name = frappe.defaults.get_user_default("supp_master_name")
|
supp_master_name = frappe.defaults.get_user_default("supp_master_name")
|
||||||
|
|
||||||
if supp_master_name == "Supplier Name":
|
fields = ["name"]
|
||||||
fields = ["name", "supplier_group"]
|
if supp_master_name != "Supplier Name":
|
||||||
else:
|
fields = ["supplier_name"]
|
||||||
fields = ["name", "supplier_name", "supplier_group"]
|
|
||||||
|
|
||||||
fields = get_fields(doctype, fields)
|
fields = get_fields(doctype, fields)
|
||||||
|
|
||||||
@ -145,6 +143,7 @@ def supplier_query(doctype, txt, searchfield, start, page_len, filters):
|
|||||||
**{"field": ", ".join(fields), "key": searchfield, "mcond": get_match_cond(doctype)}
|
**{"field": ", ".join(fields), "key": searchfield, "mcond": get_match_cond(doctype)}
|
||||||
),
|
),
|
||||||
{"txt": "%%%s%%" % txt, "_txt": txt.replace("%", ""), "start": start, "page_len": page_len},
|
{"txt": "%%%s%%" % txt, "_txt": txt.replace("%", ""), "start": start, "page_len": page_len},
|
||||||
|
as_dict=as_dict,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -61,6 +61,10 @@ frappe.ui.form.on('Loan', {
|
|||||||
},
|
},
|
||||||
|
|
||||||
refresh: function (frm) {
|
refresh: function (frm) {
|
||||||
|
if (frm.doc.repayment_schedule_type == "Pro-rated calendar months") {
|
||||||
|
frm.set_df_property("repayment_start_date", "label", "Interest Calculation Start Date");
|
||||||
|
}
|
||||||
|
|
||||||
if (frm.doc.docstatus == 1) {
|
if (frm.doc.docstatus == 1) {
|
||||||
if (["Disbursed", "Partially Disbursed"].includes(frm.doc.status) && (!frm.doc.repay_from_salary)) {
|
if (["Disbursed", "Partially Disbursed"].includes(frm.doc.status) && (!frm.doc.repay_from_salary)) {
|
||||||
frm.add_custom_button(__('Request Loan Closure'), function() {
|
frm.add_custom_button(__('Request Loan Closure'), function() {
|
||||||
@ -103,6 +107,14 @@ frappe.ui.form.on('Loan', {
|
|||||||
frm.trigger("toggle_fields");
|
frm.trigger("toggle_fields");
|
||||||
},
|
},
|
||||||
|
|
||||||
|
repayment_schedule_type: function(frm) {
|
||||||
|
if (frm.doc.repayment_schedule_type == "Pro-rated calendar months") {
|
||||||
|
frm.set_df_property("repayment_start_date", "label", "Interest Calculation Start Date");
|
||||||
|
} else {
|
||||||
|
frm.set_df_property("repayment_start_date", "label", "Repayment Start Date");
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
loan_type: function(frm) {
|
loan_type: function(frm) {
|
||||||
frm.toggle_reqd("repayment_method", frm.doc.is_term_loan);
|
frm.toggle_reqd("repayment_method", frm.doc.is_term_loan);
|
||||||
frm.toggle_display("repayment_method", frm.doc.is_term_loan);
|
frm.toggle_display("repayment_method", frm.doc.is_term_loan);
|
||||||
|
|||||||
@ -18,6 +18,7 @@
|
|||||||
"status",
|
"status",
|
||||||
"section_break_8",
|
"section_break_8",
|
||||||
"loan_type",
|
"loan_type",
|
||||||
|
"repayment_schedule_type",
|
||||||
"loan_amount",
|
"loan_amount",
|
||||||
"rate_of_interest",
|
"rate_of_interest",
|
||||||
"is_secured_loan",
|
"is_secured_loan",
|
||||||
@ -158,7 +159,8 @@
|
|||||||
"depends_on": "is_term_loan",
|
"depends_on": "is_term_loan",
|
||||||
"fieldname": "repayment_start_date",
|
"fieldname": "repayment_start_date",
|
||||||
"fieldtype": "Date",
|
"fieldtype": "Date",
|
||||||
"label": "Repayment Start Date"
|
"label": "Repayment Start Date",
|
||||||
|
"mandatory_depends_on": "is_term_loan"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fieldname": "column_break_11",
|
"fieldname": "column_break_11",
|
||||||
@ -402,12 +404,20 @@
|
|||||||
"fieldname": "is_npa",
|
"fieldname": "is_npa",
|
||||||
"fieldtype": "Check",
|
"fieldtype": "Check",
|
||||||
"label": "Is NPA"
|
"label": "Is NPA"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"depends_on": "is_term_loan",
|
||||||
|
"fetch_from": "loan_type.repayment_schedule_type",
|
||||||
|
"fieldname": "repayment_schedule_type",
|
||||||
|
"fieldtype": "Data",
|
||||||
|
"label": "Repayment Schedule Type",
|
||||||
|
"read_only": 1
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"index_web_pages_for_search": 1,
|
"index_web_pages_for_search": 1,
|
||||||
"is_submittable": 1,
|
"is_submittable": 1,
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2022-07-12 11:50:31.957360",
|
"modified": "2022-09-30 10:36:47.902903",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Loan Management",
|
"module": "Loan Management",
|
||||||
"name": "Loan",
|
"name": "Loan",
|
||||||
|
|||||||
@ -7,7 +7,16 @@ import math
|
|||||||
|
|
||||||
import frappe
|
import frappe
|
||||||
from frappe import _
|
from frappe import _
|
||||||
from frappe.utils import add_months, flt, get_last_day, getdate, now_datetime, nowdate
|
from frappe.utils import (
|
||||||
|
add_days,
|
||||||
|
add_months,
|
||||||
|
date_diff,
|
||||||
|
flt,
|
||||||
|
get_last_day,
|
||||||
|
getdate,
|
||||||
|
now_datetime,
|
||||||
|
nowdate,
|
||||||
|
)
|
||||||
|
|
||||||
import erpnext
|
import erpnext
|
||||||
from erpnext.accounts.doctype.journal_entry.journal_entry import get_payment_entry
|
from erpnext.accounts.doctype.journal_entry.journal_entry import get_payment_entry
|
||||||
@ -107,30 +116,81 @@ class Loan(AccountsController):
|
|||||||
if not self.repayment_start_date:
|
if not self.repayment_start_date:
|
||||||
frappe.throw(_("Repayment Start Date is mandatory for term loans"))
|
frappe.throw(_("Repayment Start Date is mandatory for term loans"))
|
||||||
|
|
||||||
|
schedule_type_details = frappe.db.get_value(
|
||||||
|
"Loan Type", self.loan_type, ["repayment_schedule_type", "repayment_date_on"], as_dict=1
|
||||||
|
)
|
||||||
|
|
||||||
self.repayment_schedule = []
|
self.repayment_schedule = []
|
||||||
payment_date = self.repayment_start_date
|
payment_date = self.repayment_start_date
|
||||||
balance_amount = self.loan_amount
|
balance_amount = self.loan_amount
|
||||||
while balance_amount > 0:
|
|
||||||
interest_amount = flt(balance_amount * flt(self.rate_of_interest) / (12 * 100))
|
|
||||||
principal_amount = self.monthly_repayment_amount - interest_amount
|
|
||||||
balance_amount = flt(balance_amount + interest_amount - self.monthly_repayment_amount)
|
|
||||||
if balance_amount < 0:
|
|
||||||
principal_amount += balance_amount
|
|
||||||
balance_amount = 0.0
|
|
||||||
|
|
||||||
total_payment = principal_amount + interest_amount
|
while balance_amount > 0:
|
||||||
self.append(
|
interest_amount, principal_amount, balance_amount, total_payment = self.get_amounts(
|
||||||
"repayment_schedule",
|
payment_date,
|
||||||
{
|
balance_amount,
|
||||||
"payment_date": payment_date,
|
schedule_type_details.repayment_schedule_type,
|
||||||
"principal_amount": principal_amount,
|
schedule_type_details.repayment_date_on,
|
||||||
"interest_amount": interest_amount,
|
|
||||||
"total_payment": total_payment,
|
|
||||||
"balance_loan_amount": balance_amount,
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
next_payment_date = add_single_month(payment_date)
|
|
||||||
payment_date = next_payment_date
|
if schedule_type_details.repayment_schedule_type == "Pro-rated calendar months":
|
||||||
|
next_payment_date = get_last_day(payment_date)
|
||||||
|
if schedule_type_details.repayment_date_on == "Start of the next month":
|
||||||
|
next_payment_date = add_days(next_payment_date, 1)
|
||||||
|
|
||||||
|
payment_date = next_payment_date
|
||||||
|
|
||||||
|
self.add_repayment_schedule_row(
|
||||||
|
payment_date, principal_amount, interest_amount, total_payment, balance_amount
|
||||||
|
)
|
||||||
|
|
||||||
|
if (
|
||||||
|
schedule_type_details.repayment_schedule_type == "Monthly as per repayment start date"
|
||||||
|
or schedule_type_details.repayment_date_on == "End of the current month"
|
||||||
|
):
|
||||||
|
next_payment_date = add_single_month(payment_date)
|
||||||
|
payment_date = next_payment_date
|
||||||
|
|
||||||
|
def get_amounts(self, payment_date, balance_amount, schedule_type, repayment_date_on):
|
||||||
|
if schedule_type == "Monthly as per repayment start date":
|
||||||
|
days = 1
|
||||||
|
months = 12
|
||||||
|
else:
|
||||||
|
expected_payment_date = get_last_day(payment_date)
|
||||||
|
if repayment_date_on == "Start of the next month":
|
||||||
|
expected_payment_date = add_days(expected_payment_date, 1)
|
||||||
|
|
||||||
|
if expected_payment_date == payment_date:
|
||||||
|
# using 30 days for calculating interest for all full months
|
||||||
|
days = 30
|
||||||
|
months = 365
|
||||||
|
else:
|
||||||
|
days = date_diff(get_last_day(payment_date), payment_date)
|
||||||
|
months = 365
|
||||||
|
|
||||||
|
interest_amount = flt(balance_amount * flt(self.rate_of_interest) * days / (months * 100))
|
||||||
|
principal_amount = self.monthly_repayment_amount - interest_amount
|
||||||
|
balance_amount = flt(balance_amount + interest_amount - self.monthly_repayment_amount)
|
||||||
|
if balance_amount < 0:
|
||||||
|
principal_amount += balance_amount
|
||||||
|
balance_amount = 0.0
|
||||||
|
|
||||||
|
total_payment = principal_amount + interest_amount
|
||||||
|
|
||||||
|
return interest_amount, principal_amount, balance_amount, total_payment
|
||||||
|
|
||||||
|
def add_repayment_schedule_row(
|
||||||
|
self, payment_date, principal_amount, interest_amount, total_payment, balance_loan_amount
|
||||||
|
):
|
||||||
|
self.append(
|
||||||
|
"repayment_schedule",
|
||||||
|
{
|
||||||
|
"payment_date": payment_date,
|
||||||
|
"principal_amount": principal_amount,
|
||||||
|
"interest_amount": interest_amount,
|
||||||
|
"total_payment": total_payment,
|
||||||
|
"balance_loan_amount": balance_loan_amount,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
def set_repayment_period(self):
|
def set_repayment_period(self):
|
||||||
if self.repayment_method == "Repay Fixed Amount per Period":
|
if self.repayment_method == "Repay Fixed Amount per Period":
|
||||||
|
|||||||
@ -4,7 +4,16 @@
|
|||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import frappe
|
import frappe
|
||||||
from frappe.utils import add_days, add_months, add_to_date, date_diff, flt, get_datetime, nowdate
|
from frappe.utils import (
|
||||||
|
add_days,
|
||||||
|
add_months,
|
||||||
|
add_to_date,
|
||||||
|
date_diff,
|
||||||
|
flt,
|
||||||
|
format_date,
|
||||||
|
get_datetime,
|
||||||
|
nowdate,
|
||||||
|
)
|
||||||
|
|
||||||
from erpnext.loan_management.doctype.loan.loan import (
|
from erpnext.loan_management.doctype.loan.loan import (
|
||||||
make_loan_write_off,
|
make_loan_write_off,
|
||||||
@ -47,6 +56,51 @@ class TestLoan(unittest.TestCase):
|
|||||||
loan_account="Loan Account - _TC",
|
loan_account="Loan Account - _TC",
|
||||||
interest_income_account="Interest Income Account - _TC",
|
interest_income_account="Interest Income Account - _TC",
|
||||||
penalty_income_account="Penalty Income Account - _TC",
|
penalty_income_account="Penalty Income Account - _TC",
|
||||||
|
repayment_schedule_type="Monthly as per repayment start date",
|
||||||
|
)
|
||||||
|
|
||||||
|
create_loan_type(
|
||||||
|
"Term Loan Type 1",
|
||||||
|
12000,
|
||||||
|
7.5,
|
||||||
|
is_term_loan=1,
|
||||||
|
mode_of_payment="Cash",
|
||||||
|
disbursement_account="Disbursement Account - _TC",
|
||||||
|
payment_account="Payment Account - _TC",
|
||||||
|
loan_account="Loan Account - _TC",
|
||||||
|
interest_income_account="Interest Income Account - _TC",
|
||||||
|
penalty_income_account="Penalty Income Account - _TC",
|
||||||
|
repayment_schedule_type="Monthly as per repayment start date",
|
||||||
|
)
|
||||||
|
|
||||||
|
create_loan_type(
|
||||||
|
"Term Loan Type 2",
|
||||||
|
12000,
|
||||||
|
7.5,
|
||||||
|
is_term_loan=1,
|
||||||
|
mode_of_payment="Cash",
|
||||||
|
disbursement_account="Disbursement Account - _TC",
|
||||||
|
payment_account="Payment Account - _TC",
|
||||||
|
loan_account="Loan Account - _TC",
|
||||||
|
interest_income_account="Interest Income Account - _TC",
|
||||||
|
penalty_income_account="Penalty Income Account - _TC",
|
||||||
|
repayment_schedule_type="Pro-rated calendar months",
|
||||||
|
repayment_date_on="Start of the next month",
|
||||||
|
)
|
||||||
|
|
||||||
|
create_loan_type(
|
||||||
|
"Term Loan Type 3",
|
||||||
|
12000,
|
||||||
|
7.5,
|
||||||
|
is_term_loan=1,
|
||||||
|
mode_of_payment="Cash",
|
||||||
|
disbursement_account="Disbursement Account - _TC",
|
||||||
|
payment_account="Payment Account - _TC",
|
||||||
|
loan_account="Loan Account - _TC",
|
||||||
|
interest_income_account="Interest Income Account - _TC",
|
||||||
|
penalty_income_account="Penalty Income Account - _TC",
|
||||||
|
repayment_schedule_type="Pro-rated calendar months",
|
||||||
|
repayment_date_on="End of the current month",
|
||||||
)
|
)
|
||||||
|
|
||||||
create_loan_type(
|
create_loan_type(
|
||||||
@ -62,6 +116,7 @@ class TestLoan(unittest.TestCase):
|
|||||||
"Loan Account - _TC",
|
"Loan Account - _TC",
|
||||||
"Interest Income Account - _TC",
|
"Interest Income Account - _TC",
|
||||||
"Penalty Income Account - _TC",
|
"Penalty Income Account - _TC",
|
||||||
|
repayment_schedule_type="Monthly as per repayment start date",
|
||||||
)
|
)
|
||||||
|
|
||||||
create_loan_type(
|
create_loan_type(
|
||||||
@ -902,6 +957,69 @@ class TestLoan(unittest.TestCase):
|
|||||||
amounts = calculate_amounts(loan.name, add_days(last_date, 5))
|
amounts = calculate_amounts(loan.name, add_days(last_date, 5))
|
||||||
self.assertEqual(flt(amounts["pending_principal_amount"], 0), 0)
|
self.assertEqual(flt(amounts["pending_principal_amount"], 0), 0)
|
||||||
|
|
||||||
|
def test_term_loan_schedule_types(self):
|
||||||
|
loan = create_loan(
|
||||||
|
self.applicant1,
|
||||||
|
"Term Loan Type 1",
|
||||||
|
12000,
|
||||||
|
"Repay Over Number of Periods",
|
||||||
|
12,
|
||||||
|
repayment_start_date="2022-10-17",
|
||||||
|
)
|
||||||
|
|
||||||
|
# Check for first, second and last installment date
|
||||||
|
self.assertEqual(
|
||||||
|
format_date(loan.get("repayment_schedule")[0].payment_date, "dd-MM-yyyy"), "17-10-2022"
|
||||||
|
)
|
||||||
|
self.assertEqual(
|
||||||
|
format_date(loan.get("repayment_schedule")[1].payment_date, "dd-MM-yyyy"), "17-11-2022"
|
||||||
|
)
|
||||||
|
self.assertEqual(
|
||||||
|
format_date(loan.get("repayment_schedule")[-1].payment_date, "dd-MM-yyyy"), "17-09-2023"
|
||||||
|
)
|
||||||
|
|
||||||
|
loan.loan_type = "Term Loan Type 2"
|
||||||
|
loan.save()
|
||||||
|
|
||||||
|
# Check for first, second and last installment date
|
||||||
|
self.assertEqual(
|
||||||
|
format_date(loan.get("repayment_schedule")[0].payment_date, "dd-MM-yyyy"), "01-11-2022"
|
||||||
|
)
|
||||||
|
self.assertEqual(
|
||||||
|
format_date(loan.get("repayment_schedule")[1].payment_date, "dd-MM-yyyy"), "01-12-2022"
|
||||||
|
)
|
||||||
|
self.assertEqual(
|
||||||
|
format_date(loan.get("repayment_schedule")[-1].payment_date, "dd-MM-yyyy"), "01-10-2023"
|
||||||
|
)
|
||||||
|
|
||||||
|
loan.loan_type = "Term Loan Type 3"
|
||||||
|
loan.save()
|
||||||
|
|
||||||
|
# Check for first, second and last installment date
|
||||||
|
self.assertEqual(
|
||||||
|
format_date(loan.get("repayment_schedule")[0].payment_date, "dd-MM-yyyy"), "31-10-2022"
|
||||||
|
)
|
||||||
|
self.assertEqual(
|
||||||
|
format_date(loan.get("repayment_schedule")[1].payment_date, "dd-MM-yyyy"), "30-11-2022"
|
||||||
|
)
|
||||||
|
self.assertEqual(
|
||||||
|
format_date(loan.get("repayment_schedule")[-1].payment_date, "dd-MM-yyyy"), "30-09-2023"
|
||||||
|
)
|
||||||
|
|
||||||
|
loan.repayment_method = "Repay Fixed Amount per Period"
|
||||||
|
loan.monthly_repayment_amount = 1042
|
||||||
|
loan.save()
|
||||||
|
|
||||||
|
self.assertEqual(
|
||||||
|
format_date(loan.get("repayment_schedule")[0].payment_date, "dd-MM-yyyy"), "31-10-2022"
|
||||||
|
)
|
||||||
|
self.assertEqual(
|
||||||
|
format_date(loan.get("repayment_schedule")[1].payment_date, "dd-MM-yyyy"), "30-11-2022"
|
||||||
|
)
|
||||||
|
self.assertEqual(
|
||||||
|
format_date(loan.get("repayment_schedule")[-1].payment_date, "dd-MM-yyyy"), "30-09-2023"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def create_loan_scenario_for_penalty(doc):
|
def create_loan_scenario_for_penalty(doc):
|
||||||
pledge = [{"loan_security": "Test Security 1", "qty": 4000.00}]
|
pledge = [{"loan_security": "Test Security 1", "qty": 4000.00}]
|
||||||
@ -1033,6 +1151,8 @@ def create_loan_type(
|
|||||||
penalty_income_account=None,
|
penalty_income_account=None,
|
||||||
repayment_method=None,
|
repayment_method=None,
|
||||||
repayment_periods=None,
|
repayment_periods=None,
|
||||||
|
repayment_schedule_type=None,
|
||||||
|
repayment_date_on=None,
|
||||||
):
|
):
|
||||||
|
|
||||||
if not frappe.db.exists("Loan Type", loan_name):
|
if not frappe.db.exists("Loan Type", loan_name):
|
||||||
@ -1042,6 +1162,7 @@ def create_loan_type(
|
|||||||
"company": "_Test Company",
|
"company": "_Test Company",
|
||||||
"loan_name": loan_name,
|
"loan_name": loan_name,
|
||||||
"is_term_loan": is_term_loan,
|
"is_term_loan": is_term_loan,
|
||||||
|
"repayment_schedule_type": "Monthly as per repayment start date",
|
||||||
"maximum_loan_amount": maximum_loan_amount,
|
"maximum_loan_amount": maximum_loan_amount,
|
||||||
"rate_of_interest": rate_of_interest,
|
"rate_of_interest": rate_of_interest,
|
||||||
"penalty_interest_rate": penalty_interest_rate,
|
"penalty_interest_rate": penalty_interest_rate,
|
||||||
@ -1056,8 +1177,14 @@ def create_loan_type(
|
|||||||
"repayment_periods": repayment_periods,
|
"repayment_periods": repayment_periods,
|
||||||
"write_off_amount": 100,
|
"write_off_amount": 100,
|
||||||
}
|
}
|
||||||
).insert()
|
)
|
||||||
|
|
||||||
|
if loan_type.is_term_loan:
|
||||||
|
loan_type.repayment_schedule_type = repayment_schedule_type
|
||||||
|
if loan_type.repayment_schedule_type != "Monthly as per repayment start date":
|
||||||
|
loan_type.repayment_date_on = repayment_date_on
|
||||||
|
|
||||||
|
loan_type.insert()
|
||||||
loan_type.submit()
|
loan_type.submit()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -16,6 +16,8 @@
|
|||||||
"company",
|
"company",
|
||||||
"is_term_loan",
|
"is_term_loan",
|
||||||
"disabled",
|
"disabled",
|
||||||
|
"repayment_schedule_type",
|
||||||
|
"repayment_date_on",
|
||||||
"description",
|
"description",
|
||||||
"account_details_section",
|
"account_details_section",
|
||||||
"mode_of_payment",
|
"mode_of_payment",
|
||||||
@ -157,12 +159,30 @@
|
|||||||
"label": "Disbursement Account",
|
"label": "Disbursement Account",
|
||||||
"options": "Account",
|
"options": "Account",
|
||||||
"reqd": 1
|
"reqd": 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"depends_on": "is_term_loan",
|
||||||
|
"description": "The schedule type that will be used for generating the term loan schedules (will affect the payment date and monthly repayment amount)",
|
||||||
|
"fieldname": "repayment_schedule_type",
|
||||||
|
"fieldtype": "Select",
|
||||||
|
"label": "Repayment Schedule Type",
|
||||||
|
"mandatory_depends_on": "is_term_loan",
|
||||||
|
"options": "\nMonthly as per repayment start date\nPro-rated calendar months"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"depends_on": "eval:doc.repayment_schedule_type == \"Pro-rated calendar months\"",
|
||||||
|
"description": "Select whether the repayment date should be the end of the current month or start of the upcoming month",
|
||||||
|
"fieldname": "repayment_date_on",
|
||||||
|
"fieldtype": "Select",
|
||||||
|
"label": "Repayment Date On",
|
||||||
|
"mandatory_depends_on": "eval:doc.repayment_schedule_type == \"Pro-rated calendar months\"",
|
||||||
|
"options": "\nStart of the next month\nEnd of the current month"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"index_web_pages_for_search": 1,
|
"index_web_pages_for_search": 1,
|
||||||
"is_submittable": 1,
|
"is_submittable": 1,
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2022-01-25 16:23:57.009349",
|
"modified": "2022-10-22 17:43:03.954201",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Loan Management",
|
"module": "Loan Management",
|
||||||
"name": "Loan Type",
|
"name": "Loan Type",
|
||||||
|
|||||||
@ -315,4 +315,5 @@ erpnext.patches.v14_0.fix_crm_no_of_employees
|
|||||||
erpnext.patches.v14_0.create_accounting_dimensions_in_subcontracting_doctypes
|
erpnext.patches.v14_0.create_accounting_dimensions_in_subcontracting_doctypes
|
||||||
erpnext.patches.v14_0.fix_subcontracting_receipt_gl_entries
|
erpnext.patches.v14_0.fix_subcontracting_receipt_gl_entries
|
||||||
erpnext.patches.v14_0.migrate_remarks_from_gl_to_payment_ledger
|
erpnext.patches.v14_0.migrate_remarks_from_gl_to_payment_ledger
|
||||||
|
erpnext.patches.v13_0.update_schedule_type_in_loans
|
||||||
erpnext.patches.v14_0.create_accounting_dimensions_for_asset_capitalization
|
erpnext.patches.v14_0.create_accounting_dimensions_for_asset_capitalization
|
||||||
|
|||||||
14
erpnext/patches/v13_0/update_schedule_type_in_loans.py
Normal file
14
erpnext/patches/v13_0/update_schedule_type_in_loans.py
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
import frappe
|
||||||
|
|
||||||
|
|
||||||
|
def execute():
|
||||||
|
loan = frappe.qb.DocType("Loan")
|
||||||
|
loan_type = frappe.qb.DocType("Loan Type")
|
||||||
|
|
||||||
|
frappe.qb.update(loan_type).set(
|
||||||
|
loan_type.repayment_schedule_type, "Monthly as per repayment start date"
|
||||||
|
).where(loan_type.is_term_loan == 1).run()
|
||||||
|
|
||||||
|
frappe.qb.update(loan).set(
|
||||||
|
loan.repayment_schedule_type, "Monthly as per repayment start date"
|
||||||
|
).where(loan.is_term_loan == 1).run()
|
||||||
@ -242,20 +242,29 @@ erpnext.utils.set_taxes = function(frm, triggered_from_field) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
erpnext.utils.get_contact_details = function(frm) {
|
erpnext.utils.get_contact_details = function (frm) {
|
||||||
if (frm.updating_party_details) return;
|
if (frm.updating_party_details) return;
|
||||||
|
|
||||||
if (frm.doc["contact_person"]) {
|
if (frm.doc["contact_person"]) {
|
||||||
frappe.call({
|
frappe.call({
|
||||||
method: "frappe.contacts.doctype.contact.contact.get_contact_details",
|
method: "frappe.contacts.doctype.contact.contact.get_contact_details",
|
||||||
args: {contact: frm.doc.contact_person },
|
args: { contact: frm.doc.contact_person },
|
||||||
callback: function(r) {
|
callback: function (r) {
|
||||||
if (r.message)
|
if (r.message) frm.set_value(r.message);
|
||||||
frm.set_value(r.message);
|
},
|
||||||
}
|
});
|
||||||
})
|
} else {
|
||||||
|
frm.set_value({
|
||||||
|
contact_person: "",
|
||||||
|
contact_display: "",
|
||||||
|
contact_email: "",
|
||||||
|
contact_mobile: "",
|
||||||
|
contact_phone: "",
|
||||||
|
contact_designation: "",
|
||||||
|
contact_department: "",
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
erpnext.utils.validate_mandatory = function(frm, label, value, trigger_on) {
|
erpnext.utils.validate_mandatory = function(frm, label, value, trigger_on) {
|
||||||
if (!value) {
|
if (!value) {
|
||||||
|
|||||||
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
|
|
||||||
import frappe
|
import frappe
|
||||||
|
from frappe.custom.doctype.property_setter.property_setter import make_property_setter
|
||||||
from frappe.test_runner import make_test_records
|
from frappe.test_runner import make_test_records
|
||||||
from frappe.tests.utils import FrappeTestCase
|
from frappe.tests.utils import FrappeTestCase
|
||||||
from frappe.utils import flt
|
from frappe.utils import flt
|
||||||
@ -341,6 +342,33 @@ class TestCustomer(FrappeTestCase):
|
|||||||
due_date = get_due_date("2017-01-22", "Customer", "_Test Customer")
|
due_date = get_due_date("2017-01-22", "Customer", "_Test Customer")
|
||||||
self.assertEqual(due_date, "2017-01-22")
|
self.assertEqual(due_date, "2017-01-22")
|
||||||
|
|
||||||
|
def test_serach_fields_for_customer(self):
|
||||||
|
from erpnext.controllers.queries import customer_query
|
||||||
|
|
||||||
|
make_property_setter(
|
||||||
|
"Customer", None, "search_fields", "customer_group", "Data", for_doctype="Doctype"
|
||||||
|
)
|
||||||
|
|
||||||
|
data = customer_query(
|
||||||
|
"Customer", "_Test Customer", "", 0, 20, filters={"name": "_Test Customer"}, as_dict=True
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertEqual(data[0].name, "_Test Customer")
|
||||||
|
self.assertEqual(data[0].customer_group, "_Test Customer Group")
|
||||||
|
self.assertTrue("territory" not in data[0])
|
||||||
|
|
||||||
|
make_property_setter(
|
||||||
|
"Customer", None, "search_fields", "customer_group, territory", "Data", for_doctype="Doctype"
|
||||||
|
)
|
||||||
|
data = customer_query(
|
||||||
|
"Customer", "_Test Customer", "", 0, 20, filters={"name": "_Test Customer"}, as_dict=True
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertEqual(data[0].name, "_Test Customer")
|
||||||
|
self.assertEqual(data[0].customer_group, "_Test Customer Group")
|
||||||
|
self.assertEqual(data[0].territory, "_Test Territory")
|
||||||
|
self.assertTrue("territory" in data[0])
|
||||||
|
|
||||||
|
|
||||||
def get_customer_dict(customer_name):
|
def get_customer_dict(customer_name):
|
||||||
return {
|
return {
|
||||||
|
|||||||
@ -272,6 +272,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"collapsible": 1,
|
"collapsible": 1,
|
||||||
|
"collapsible_depends_on": "eval: doc.margin_type || doc.discount_amount",
|
||||||
"fieldname": "discount_and_margin",
|
"fieldname": "discount_and_margin",
|
||||||
"fieldtype": "Section Break",
|
"fieldtype": "Section Break",
|
||||||
"label": "Discount and Margin"
|
"label": "Discount and Margin"
|
||||||
@ -842,7 +843,7 @@
|
|||||||
"idx": 1,
|
"idx": 1,
|
||||||
"istable": 1,
|
"istable": 1,
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2022-09-06 13:24:18.065312",
|
"modified": "2022-10-26 16:05:02.712705",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Selling",
|
"module": "Selling",
|
||||||
"name": "Sales Order Item",
|
"name": "Sales Order Item",
|
||||||
|
|||||||
@ -261,6 +261,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"collapsible": 1,
|
"collapsible": 1,
|
||||||
|
"collapsible_depends_on": "eval: doc.margin_type || doc.discount_amount",
|
||||||
"fieldname": "discount_and_margin",
|
"fieldname": "discount_and_margin",
|
||||||
"fieldtype": "Section Break",
|
"fieldtype": "Section Break",
|
||||||
"label": "Discount and Margin"
|
"label": "Discount and Margin"
|
||||||
@ -814,7 +815,7 @@
|
|||||||
"index_web_pages_for_search": 1,
|
"index_web_pages_for_search": 1,
|
||||||
"istable": 1,
|
"istable": 1,
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2022-10-12 03:36:05.344847",
|
"modified": "2022-10-26 16:05:17.720768",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Stock",
|
"module": "Stock",
|
||||||
"name": "Delivery Note Item",
|
"name": "Delivery Note Item",
|
||||||
|
|||||||
@ -919,6 +919,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"collapsible": 1,
|
"collapsible": 1,
|
||||||
|
"collapsible_depends_on": "eval: doc.margin_type || doc.discount_amount",
|
||||||
"fieldname": "discount_and_margin_section",
|
"fieldname": "discount_and_margin_section",
|
||||||
"fieldtype": "Section Break",
|
"fieldtype": "Section Break",
|
||||||
"label": "Discount and Margin"
|
"label": "Discount and Margin"
|
||||||
@ -1000,7 +1001,7 @@
|
|||||||
"idx": 1,
|
"idx": 1,
|
||||||
"istable": 1,
|
"istable": 1,
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2022-10-12 03:37:59.516609",
|
"modified": "2022-10-26 16:06:02.524435",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Stock",
|
"module": "Stock",
|
||||||
"name": "Purchase Receipt Item",
|
"name": "Purchase Receipt Item",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user