mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-20 13:39:18 +00:00
feat: validation for if no slab found
This commit is contained in:
@@ -122,24 +122,31 @@ def calculate_gratuity_amount(employee, gratuity_rule, experience):
|
|||||||
calculate_gratuity_amount_based_on = frappe.db.get_value("Gratuity Rule", gratuity_rule, "calculate_gratuity_amount_based_on")
|
calculate_gratuity_amount_based_on = frappe.db.get_value("Gratuity Rule", gratuity_rule, "calculate_gratuity_amount_based_on")
|
||||||
|
|
||||||
gratuity_amount = 0
|
gratuity_amount = 0
|
||||||
fraction_to_be_paid = 0
|
slab_found = False
|
||||||
year_left = experience
|
year_left = experience
|
||||||
for slab in slabs:
|
for slab in slabs:
|
||||||
if calculate_gratuity_amount_based_on == "Current Slab":
|
if calculate_gratuity_amount_based_on == "Current Slab":
|
||||||
if experience >= slab.from_year and (slab.to_year == 0 or experience < slab.to_year):
|
if experience >= slab.from_year and (slab.to_year == 0 or experience < slab.to_year):
|
||||||
gratuity_amount = total_applicable_components_amount * experience * slab.fraction_of_applicable_earnings
|
gratuity_amount = total_applicable_components_amount * experience * slab.fraction_of_applicable_earnings
|
||||||
if slab.fraction_of_applicable_earnings:
|
if slab.fraction_of_applicable_earnings:
|
||||||
|
slab_found = True
|
||||||
break
|
break
|
||||||
elif calculate_gratuity_amount_based_on == "Sum of all previous slabs":
|
elif calculate_gratuity_amount_based_on == "Sum of all previous slabs":
|
||||||
if slab.to_year == 0 and slab.from_year == 0:
|
if slab.to_year == 0 and slab.from_year == 0:
|
||||||
gratuity_amount += year_left * total_applicable_components_amount * slab.fraction_of_applicable_earnings
|
gratuity_amount += year_left * total_applicable_components_amount * slab.fraction_of_applicable_earnings
|
||||||
|
slab_found = True
|
||||||
break
|
break
|
||||||
|
|
||||||
if experience > slab.to_year and experience > slab.from_year:
|
if experience > slab.to_year and experience > slab.from_year:
|
||||||
gratuity_amount += (slab.to_year - slab.from_year) * total_applicable_components_amount * slab.fraction_of_applicable_earnings
|
gratuity_amount += (slab.to_year - slab.from_year) * total_applicable_components_amount * slab.fraction_of_applicable_earnings
|
||||||
year_left -= (slab.to_year - slab.from_year)
|
year_left -= (slab.to_year - slab.from_year)
|
||||||
|
slab_found = True
|
||||||
elif slab.from_year <= experience < slab.to_year:
|
elif slab.from_year <= experience < slab.to_year:
|
||||||
gratuity_amount += year_left * total_applicable_components_amount * slab.fraction_of_applicable_earnings
|
gratuity_amount += year_left * total_applicable_components_amount * slab.fraction_of_applicable_earnings
|
||||||
|
slab_found = True
|
||||||
|
|
||||||
|
if not slab_found:
|
||||||
|
frappe.throw(_("No Suitable Slab found for Calculation of gratuity amount in Gratuity Rule: {0}").format(bold(gratuity_rule)))
|
||||||
|
|
||||||
|
|
||||||
return gratuity_amount
|
return gratuity_amount
|
||||||
|
|||||||
Reference in New Issue
Block a user