Skip to content

Commit

Permalink
chore: validations for tables in company loan section and add collect…
Browse files Browse the repository at this point in the history
…ion_offset_sequence_for_settlement_collection (#112)
  • Loading branch information
anandbaburajan authored Oct 26, 2023
1 parent d32ef21 commit 05ab366
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 18 deletions.
12 changes: 5 additions & 7 deletions lending/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,11 @@
# ---------------
# Hook on document methods and events

# doc_events = {
# "*": {
# "on_update": "method",
# "on_cancel": "method",
# "on_trash": "method"
# }
# }
doc_events = {
"Company": {
"validate": "lending.overrides.company.validate_loan_tables",
}
}

# Scheduled Tasks
# ---------------
Expand Down
9 changes: 8 additions & 1 deletion lending/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,17 @@
"options": "IP...IP...IP...CCC\nPPP...III...CCC",
"insert_after": "collection_offset_sequence_for_standard_asset",
},
{
"fieldname": "collection_offset_sequence_for_settlement_collection",
"label": "Collection Offset Sequence for Settlement Collection",
"fieldtype": "Select",
"options": "IP...IP...IP...CCC\nPPP...III...CCC",
"insert_after": "collection_offset_sequence_for_written_off_asset",
},
{
"fieldname": "loan_section_break_2",
"fieldtype": "Section Break",
"insert_after": "collection_offset_sequence_for_written_off_asset",
"insert_after": "collection_offset_sequence_for_settlement_collection",
},
{
"fieldname": "loan_classification_ranges",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,14 @@
"field_order": [
"classification_code",
"classification_name",
"security_type",
"min_dpd_range",
"max_dpd_range",
"loan_product",
"provision_rate"
],
"fields": [
{
"columns": 1,
"fieldname": "loan_product",
"fieldtype": "Select",
"in_list_view": 1,
"label": "Loan Product",
"options": "Secured\nUnsecured\nSemi-Secured"
},
{
"fieldname": "provision_rate",
"fieldtype": "Percent",
"in_list_view": 1,
Expand Down Expand Up @@ -59,12 +52,20 @@
"in_list_view": 1,
"label": "Classification Name",
"read_only": 1
},
{
"columns": 2,
"fieldname": "security_type",
"fieldtype": "Select",
"in_list_view": 1,
"label": "Security Type",
"options": "Secured\nUnsecured\nSemi-Secured"
}
],
"index_web_pages_for_search": 1,
"istable": 1,
"links": [],
"modified": "2023-09-13 21:39:55.163737",
"modified": "2023-10-26 11:44:17.642540",
"modified_by": "Administrator",
"module": "Loan Management",
"name": "Loan IRAC Provisioning Configuration",
Expand Down
24 changes: 24 additions & 0 deletions lending/overrides/company.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import frappe
from frappe import _


def validate_loan_tables(doc, method=None):
loan_classification_ranges = []
for d in doc.loan_classification_ranges:
if d.classification_code not in loan_classification_ranges:
loan_classification_ranges.append(d.classification_code)
else:
frappe.throw(
_("Classification {0} added multiple times").format(frappe.bold(d.classification_code))
)

irac_provisioning_configurations = []
for d in doc.irac_provisioning_configuration:
if (d.classification_code, d.security_type) not in irac_provisioning_configurations:
irac_provisioning_configurations.append((d.classification_code, d.security_type))
else:
frappe.throw(
_("Classification {0} with security type {1} added multiple times").format(
frappe.bold(d.classification_code), frappe.bold(d.security_type)
)
)
4 changes: 3 additions & 1 deletion lending/patches.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@ lending.patches.v15_0.rename_loan_partner_charge_type
lending.patches.v15_0.migrate_loan_type_to_loan_product
lending.patches.v15_0.add_loan_product_code_and_rename_loan_name
lending.patches.v15_0.update_penalty_interest_method_in_loan_products
lending.patches.v15_0.update_min_bpi_application_days
lending.patches.v15_0.update_min_bpi_application_days
lending.patches.v15_0.create_custom_field_for_collection_offset_sequence_for_settlement_collection
lending.patches.v15_0.rename_irac_provisioning_configuration_loan_product
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Copyright (c) 2023, Frappe Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt


import frappe
from frappe.custom.doctype.custom_field.custom_field import create_custom_fields


def execute():
create_custom_fields(
{
"Company": [
{
"fieldname": "collection_offset_sequence_for_settlement_collection",
"label": "Collection Offset Sequence for Settlement Collection",
"fieldtype": "Select",
"options": "IP...IP...IP...CCC\nPPP...III...CCC",
"insert_after": "collection_offset_sequence_for_written_off_asset",
},
]
},
ignore_validate=True,
)

frappe.db.set_value(
"Custom Field",
{"name": "Company-loan_section_break_2"},
"insert_after",
"collection_offset_sequence_for_settlement_collection",
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright (c) 2023, Frappe Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt


from frappe.model.utils.rename_field import rename_field


def execute():
try:
rename_field("Loan IRAC Provisioning Configuration", "loan_product", "security_type")

except Exception as e:
if e.args[0] != 1054:
raise

0 comments on commit 05ab366

Please sign in to comment.