diff --git a/lending/hooks.py b/lending/hooks.py index e00f3d55..503ed4c8 100644 --- a/lending/hooks.py +++ b/lending/hooks.py @@ -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 # --------------- diff --git a/lending/install.py b/lending/install.py index f9d23b20..5b941e6c 100644 --- a/lending/install.py +++ b/lending/install.py @@ -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", diff --git a/lending/loan_management/doctype/loan_irac_provisioning_configuration/loan_irac_provisioning_configuration.json b/lending/loan_management/doctype/loan_irac_provisioning_configuration/loan_irac_provisioning_configuration.json index 54f71bc5..36ded6c7 100644 --- a/lending/loan_management/doctype/loan_irac_provisioning_configuration/loan_irac_provisioning_configuration.json +++ b/lending/loan_management/doctype/loan_irac_provisioning_configuration/loan_irac_provisioning_configuration.json @@ -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, @@ -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", diff --git a/lending/overrides/company.py b/lending/overrides/company.py new file mode 100644 index 00000000..01272a4e --- /dev/null +++ b/lending/overrides/company.py @@ -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) + ) + ) diff --git a/lending/patches.txt b/lending/patches.txt index e20037fa..be7526cb 100644 --- a/lending/patches.txt +++ b/lending/patches.txt @@ -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 \ No newline at end of file +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 \ No newline at end of file diff --git a/lending/patches/v15_0/create_custom_field_for_collection_offset_sequence_for_settlement_collection.py b/lending/patches/v15_0/create_custom_field_for_collection_offset_sequence_for_settlement_collection.py new file mode 100644 index 00000000..b85bd87b --- /dev/null +++ b/lending/patches/v15_0/create_custom_field_for_collection_offset_sequence_for_settlement_collection.py @@ -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", + ) diff --git a/lending/patches/v15_0/rename_irac_provisioning_configuration_loan_product.py b/lending/patches/v15_0/rename_irac_provisioning_configuration_loan_product.py new file mode 100644 index 00000000..e95b9f50 --- /dev/null +++ b/lending/patches/v15_0/rename_irac_provisioning_configuration_loan_product.py @@ -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