diff --git a/erpnext/payroll/doctype/gratuity/gratuity.py b/erpnext/payroll/doctype/gratuity/gratuity.py index 6b624140e2..9f59280393 100644 --- a/erpnext/payroll/doctype/gratuity/gratuity.py +++ b/erpnext/payroll/doctype/gratuity/gratuity.py @@ -6,7 +6,7 @@ from __future__ import unicode_literals import frappe from frappe import _, bold from frappe.model.document import Document -from frappe.utils import flt, get_datetime +from frappe.utils import flt, get_datetime, get_link_to_form from math import floor from frappe.utils import get_datetime @@ -43,8 +43,7 @@ class Gratuity(Document): """, (self.name, self.employee), as_dict=1)[0].paid_amount if flt(paid_amount) > self.amount: - frappe.throw(_("Row {0}# Paid Amount cannot be greater than Total amount"), - EmployeeAdvanceOverPayment) + frappe.throw(_("Row {0}# Paid Amount cannot be greater than Total amount")) self.db_set("paid_amount", paid_amount) @@ -65,7 +64,7 @@ def calculate_work_experience(employee, gratuity_rule): date_of_joining, relieving_date = frappe.db.get_value('Employee', employee, ['date_of_joining', 'relieving_date']) if not relieving_date: - frappe.throw(_("Please set Relieving Date for employee: {0}").format(bold(employee))) + frappe.throw(_("Please set Relieving Date for employee: {0}").format(bold(get_link_to_form("Employee", employee)))) method = frappe.db.get_value("Gratuity Rule", gratuity_rule, "work_experience_calculation_function") @@ -108,11 +107,13 @@ def get_non_working_days(employee, relieving_date, status): filters["leave_type"] = ("IN", lwp_leave_types) - record = frappe.get_all("Attendance", filters=filters, fields = ["COUNT(name) as total_lwp"], debug = 1) + record = frappe.get_all("Attendance", filters=filters, fields = ["COUNT(name) as total_lwp"]) return record[0].total_lwp if len(record) else 0 def calculate_gratuity_amount(employee, gratuity_rule, experience): applicable_earnings_component = frappe.get_all("Gratuity Applicable Component", filters= {'parent': gratuity_rule}, fields=["salary_component"]) + if len(applicable_earnings_component) == 0: + frappe.throw(_("No Applicable Earnings Component found for Gratuity Rule: {0}").format(bold(get_link_to_form("Gratuity Rule",gratuity_rule)))) applicable_earnings_component = [component.salary_component for component in applicable_earnings_component] slabs = get_gratuity_rule_slabs(gratuity_rule) @@ -137,16 +138,16 @@ def calculate_gratuity_amount(employee, gratuity_rule, experience): slab_found = True break - if experience > slab.to_year and experience > slab.from_year: + if experience > slab.to_year and experience > slab.from_year and slab.to_year !=0: 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) slab_found = True - elif slab.from_year <= experience < slab.to_year: + elif slab.from_year <= experience and (experience < slab.to_year or slab.to_year == 0): 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))) + 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 @@ -174,7 +175,7 @@ def get_total_applicable_component_amount(employee, applicable_earnings_componen return total_applicable_components_amount def get_gratuity_rule_slabs(gratuity_rule): - return frappe.get_all("Gratuity Rule Slab", filters= {'parent': gratuity_rule}, fields = ["*"]) + return frappe.get_all("Gratuity Rule Slab", filters= {'parent': gratuity_rule}, fields = ["*"], order_by="idx") def get_salary_structure(employee): return frappe.get_list("Salary Structure Assignment", filters = {"employee": employee, 'docstatus': 1}, fields=["from_date", "salary_structure"], order_by = "from_date desc")[0].salary_structure diff --git a/erpnext/payroll/doctype/gratuity_rule/gratuity_rule.js b/erpnext/payroll/doctype/gratuity_rule/gratuity_rule.js index feaf6a8e18..69099bb39d 100644 --- a/erpnext/payroll/doctype/gratuity_rule/gratuity_rule.js +++ b/erpnext/payroll/doctype/gratuity_rule/gratuity_rule.js @@ -19,6 +19,7 @@ frappe.ui.form.on('Gratuity Rule Slab', { So, on row addition setting current_row.from = previous row.to. On to_year insert we have to check that it is not less than from_year + Wrong order may lead to Wrong Calculation */ @@ -33,7 +34,7 @@ frappe.ui.form.on('Gratuity Rule Slab', { to_year(frm, cdt, cdn) { let row = locals[cdt][cdn]; - if (row.to_year <= row.from_year){ + if (row.to_year <= row.from_year && row.to_year === 0){ frappe.throw(__("To(Year) year can not be less than From(year) ")); } } diff --git a/erpnext/payroll/doctype/gratuity_rule/gratuity_rule.json b/erpnext/payroll/doctype/gratuity_rule/gratuity_rule.json index 41d5a97641..18053ba88e 100644 --- a/erpnext/payroll/doctype/gratuity_rule/gratuity_rule.json +++ b/erpnext/payroll/doctype/gratuity_rule/gratuity_rule.json @@ -28,7 +28,7 @@ "fieldtype": "Select", "in_list_view": 1, "label": "Calculate Gratuity Amount Based on", - "options": "Current slab\nSum of all previous slabs", + "options": "Current Slab\nSum of all previous slabs", "reqd": 1 }, { @@ -76,7 +76,7 @@ } ], "links": [], - "modified": "2020-08-14 16:23:05.287545", + "modified": "2020-08-17 14:17:02.594665", "modified_by": "Administrator", "module": "Payroll", "name": "Gratuity Rule", diff --git a/erpnext/payroll/doctype/gratuity_rule/gratuity_rule.py b/erpnext/payroll/doctype/gratuity_rule/gratuity_rule.py index 71adbe5b31..00b5752eb8 100644 --- a/erpnext/payroll/doctype/gratuity_rule/gratuity_rule.py +++ b/erpnext/payroll/doctype/gratuity_rule/gratuity_rule.py @@ -11,8 +11,8 @@ class GratuityRule(Document): def validate(self): for current_slab in self.gratuity_rule_slabs: - if current_slab.from_year > current_slab.to_year: - frappe(_("Row {0}: From (Year) can not be greater than To (Year)").format(slab.idx)) + if (current_slab.from_year > current_slab.to_year) and current_slab.to_year != 0: + frappe(_("Row {0}: From (Year) can not be greater than To (Year)").format(current_slab.idx)) if current_slab.to_year == 0 and current_slab.from_year == 0 and len(self.gratuity_rule_slabs) > 1: frappe.throw(_("You can not define multiple slabs if you have a slab with no lower and upper limits.")) diff --git a/erpnext/payroll/doctype/gratuity_rule_slab/gratuity_rule_slab.json b/erpnext/payroll/doctype/gratuity_rule_slab/gratuity_rule_slab.json index dd642f4cd0..bc37b0f51e 100644 --- a/erpnext/payroll/doctype/gratuity_rule_slab/gratuity_rule_slab.json +++ b/erpnext/payroll/doctype/gratuity_rule_slab/gratuity_rule_slab.json @@ -37,7 +37,7 @@ ], "istable": 1, "links": [], - "modified": "2020-08-14 15:23:12.041375", + "modified": "2020-08-17 14:09:56.781712", "modified_by": "Administrator", "module": "Payroll", "name": "Gratuity Rule Slab", diff --git a/erpnext/regional/united_arab_emirates/setup.py b/erpnext/regional/united_arab_emirates/setup.py index 690c6feedd..f23698e19b 100644 --- a/erpnext/regional/united_arab_emirates/setup.py +++ b/erpnext/regional/united_arab_emirates/setup.py @@ -161,7 +161,7 @@ def create_standard_documents(): # Rule Under Limited Contract rule_1 = frappe.new_doc("Gratuity Rule") - rule_1.name = "Rule Under Limited Contract" + rule_1.name = "Rule Under Limited Contract (UAE)" rule_1.calculate_gratuity_amount_based_on = "Sum of all previous slabs" rule_1.work_experience_calculation_method = "Take Exact Completed Years" rule_1.minimum_year_for_gratuity = 1 @@ -186,7 +186,7 @@ def create_standard_documents(): # Rule Under Unlimited Contract on termination rule_2 = frappe.new_doc("Gratuity Rule") - rule_2.name = "Rule Under Unlimited Contract on termination" + rule_2.name = "Rule Under Unlimited Contract on termination (UAE)" rule_2.calculate_gratuity_amount_based_on = "Current Slab" rule_2.work_experience_calculation_method = "Take Exact Completed Years" rule_2.minimum_year_for_gratuity = 1 @@ -211,7 +211,7 @@ def create_standard_documents(): # Rule Under Unlimited Contract rule_3 = frappe.new_doc("Gratuity Rule") - rule_3.name = "Rule Under Unlimited Contract on resignation" + rule_3.name = "Rule Under Unlimited Contract on resignation (UAE)" rule_3.calculate_gratuity_amount_based_on = "Current Slab" rule_3.work_experience_calculation_method = "Take Exact Completed Years" rule_3.minimum_year_for_gratuity = 1