Skip to content

Commit

Permalink
chore: better loan partner validations and some field changes (copy #127
Browse files Browse the repository at this point in the history
) (#128)

* chore: better loan partner validations and some field changes

(cherry picked from commit 402c9e2)

* chore: fix linting issues

(cherry picked from commit 4ef8ac8)

---------

Co-authored-by: anandbaburajan <[email protected]>
  • Loading branch information
mergify[bot] and anandbaburajan authored Nov 9, 2023
1 parent e129e72 commit bb3d635
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 24 deletions.
16 changes: 6 additions & 10 deletions lending/loan_management/doctype/loan_partner/loan_partner.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
"fldg_section",
"fldg_trigger_dpd",
"fldg_limit_calculation_component",
"fldg_total_percentage",
"column_break_szii",
"type_of_fldg_applicable",
"fldg_fixed_deposit_percentage",
Expand Down Expand Up @@ -73,10 +72,10 @@
"fieldname": "organization_type",
"fieldtype": "Select",
"label": "Organization Type",
"options": "\nCentralized\nDecentralized"
"options": "\nCentralized\nDecentralized",
"reqd": 1
},
{
"depends_on": "eval:!doc.__islocal",
"fieldname": "section_break_mpap",
"fieldtype": "Section Break",
"label": "Organization"
Expand All @@ -97,6 +96,7 @@
"read_only": 1
},
{
"depends_on": "eval:!doc.__islocal",
"fieldname": "primary_address",
"fieldtype": "Link",
"label": "Primary Address",
Expand Down Expand Up @@ -191,11 +191,6 @@
"label": "FLDG Corporate Guarantee Percentage",
"mandatory_depends_on": "eval:doc.type_of_fldg_applicable == \"Corporate Guarantee only\" || doc.type_of_fldg_applicable == \"Both Fixed Deposit and Corporate Guarantee\""
},
{
"fieldname": "fldg_total_percentage",
"fieldtype": "Percent",
"label": "FLDG Total Percentage"
},
{
"fieldname": "misc_section",
"fieldtype": "Section Break",
Expand Down Expand Up @@ -240,7 +235,8 @@
"fieldname": "partial_payment_mechanism",
"fieldtype": "Select",
"label": "Partial Payment Mechanism",
"options": "\nEMI Percentage wise sharing\nComponent wise sharing"
"options": "\nEMI Percentage wise sharing\nComponent wise sharing",
"reqd": 1
},
{
"fieldname": "column_break_xyxj",
Expand All @@ -253,7 +249,7 @@
],
"index_web_pages_for_search": 1,
"links": [],
"modified": "2023-11-03 11:30:01.230498",
"modified": "2023-11-09 14:55:36.675654",
"modified_by": "Administrator",
"module": "Loan Management",
"name": "Loan Partner",
Expand Down
35 changes: 26 additions & 9 deletions lending/loan_management/doctype/loan_partner/loan_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,11 @@ def validate_percentage_and_interest_fields(self):
fldg_fields_to_validate = []

if self.type_of_fldg_applicable == "Fixed Deposit only":
fldg_fields_to_validate = ["fldg_total_percentage", "fldg_fixed_deposit_percentage"]
fldg_fields_to_validate = ["fldg_fixed_deposit_percentage"]
elif self.type_of_fldg_applicable == "Corporate Guarantee only":
fldg_fields_to_validate = ["fldg_total_percentage", "fldg_corporate_guarantee_percentage"]
fldg_fields_to_validate = ["fldg_corporate_guarantee_percentage"]
elif self.type_of_fldg_applicable == "Both Fixed Deposit and Corporate Guarantee":
fldg_fields_to_validate = [
"fldg_total_percentage",
"fldg_fixed_deposit_percentage",
"fldg_corporate_guarantee_percentage",
]
Expand All @@ -53,11 +52,29 @@ def validate_percentage_and_interest_fields(self):
shareable.idx, frappe.bold(frappe.unscrub(field))
)
)
elif shareable.sharing_parameter == "Loan Amount Percentage":
for field in ["partner_loan_amount_percentage", "minimum_partner_loan_amount_percentage"]:
if not shareable.get(field) or shareable.get(field) < 1 or shareable.get(field) > 99:
frappe.throw(
_("Row {0}: {1} should be between 1 and 99").format(
shareable.idx, frappe.bold(frappe.unscrub(field))
)
if shareable.get(field):
shareable.set(field, 0)
elif shareable.sharing_parameter == "Loan Amount Percentage":
if (
not shareable.get("partner_loan_amount_percentage")
or shareable.get("partner_loan_amount_percentage") < 1
or shareable.get("partner_loan_amount_percentage") > 99
):
frappe.throw(
_("Row {0}: {1} should be between 1 and 99").format(
shareable.idx, frappe.bold(frappe.unscrub("partner_loan_amount_percentage"))
)
)
if shareable.get("minimum_partner_loan_amount_percentage") and (
shareable.get("minimum_partner_loan_amount_percentage") < 1
or shareable.get("minimum_partner_loan_amount_percentage") > 99
):
frappe.throw(
_("Row {0}: {1} should be between 1 and 99").format(
shareable.idx, frappe.bold(frappe.unscrub("minimum_partner_loan_amount_percentage"))
)
)
for field in ["partner_collection_percentage", "company_collection_percentage"]:
if shareable.get(field):
shareable.set(field, 0)
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,20 @@
"fieldname": "partner_collection_percentage",
"fieldtype": "Percent",
"in_list_view": 1,
"label": "Partner Collection Percentage"
"label": "Partner Collection Percentage",
"mandatory_depends_on": "eval:doc.sharing_parameter == \"Collection Percentage\""
},
{
"fieldname": "partner_loan_amount_percentage",
"fieldtype": "Percent",
"in_list_view": 1,
"label": "Partner Loan Amount Percentage"
"label": "Partner Loan Amount Percentage",
"mandatory_depends_on": "eval:doc.sharing_parameter == \"Loan Amount Percentage\""
},
{
"fieldname": "minimum_partner_loan_amount_percentage",
"fieldtype": "Percent",
"in_list_view": 1,
"label": "Minimum Partner Loan Amount Percentage"
},
{
Expand All @@ -51,14 +54,14 @@
{
"fieldname": "company_collection_percentage",
"fieldtype": "Percent",
"in_list_view": 1,
"label": "Company Collection Percentage"
"label": "Company Collection Percentage",
"mandatory_depends_on": "eval:doc.sharing_parameter == \"Collection Percentage\""
}
],
"index_web_pages_for_search": 1,
"istable": 1,
"links": [],
"modified": "2023-11-02 11:48:00.797758",
"modified": "2023-11-09 17:13:25.366680",
"modified_by": "Administrator",
"module": "Loan Management",
"name": "Loan Partner Shareable",
Expand Down

0 comments on commit bb3d635

Please sign in to comment.