Fix - depends on lwp - employee benefit (#14644)
diff --git a/erpnext/hr/doctype/employee_benefit_application/employee_benefit_application.py b/erpnext/hr/doctype/employee_benefit_application/employee_benefit_application.py
index 273857e..913eec8 100644
--- a/erpnext/hr/doctype/employee_benefit_application/employee_benefit_application.py
+++ b/erpnext/hr/doctype/employee_benefit_application/employee_benefit_application.py
@@ -164,7 +164,7 @@
lwp = cint(leave[0][1]) and (lwp + 0.5) or (lwp + 1)
return lwp
-def get_benefit_component_amount(employee, start_date, end_date, struct_row, sal_struct, payment_days, working_days, frequency):
+def get_benefit_component_amount(employee, start_date, end_date, struct_row, sal_struct, period_length, frequency):
# Considering there is only one application for an year
benefit_application_name = frappe.db.sql("""
select name from `tabEmployee Benefit Application`
@@ -177,28 +177,26 @@
'end_date': end_date
})
- payroll_period_days, actual_payroll_days = get_payroll_period_days(start_date, end_date, employee)
+ period_factor, actual_payroll_days = get_payroll_period_days(start_date, end_date, employee)
- depends_on_lwp = frappe.db.get_value("Salary Component", struct_row.salary_component, "depends_on_lwp")
- if depends_on_lwp != 1:
- payment_days = working_days
+ if frappe.db.get_value("Salary Component", struct_row.salary_component, "depends_on_lwp") != 1:
if frequency == "Monthly" and actual_payroll_days in range(360, 370):
- payment_days = 1
- payroll_period_days = 12
+ period_length = 1
+ period_factor = 12
- if payroll_period_days:
+ if period_factor:
# If there is application for benefit then fetch the amount from the application.
# else Split the max benefits to the pro-rata components with the ratio of thier max_benefit_amount
if benefit_application_name:
benefit_application = frappe.get_doc("Employee Benefit Application", benefit_application_name[0][0])
- return get_benefit_amount(benefit_application, struct_row, payroll_period_days, payment_days)
+ return get_benefit_amount(benefit_application, struct_row, period_factor, period_length)
# TODO: Check if there is benefit claim for employee then pro-rata devid the rest of amount (Late Benefit Application)
else:
component_max = frappe.db.get_value("Salary Component", struct_row.salary_component, "max_benefit_amount")
if component_max > 0:
benefit_amount = get_benefit_pro_rata_ratio_amount(sal_struct, component_max)
- return get_amount(payroll_period_days, benefit_amount, payment_days)
+ return get_amount(period_factor, benefit_amount, period_length)
return False
def get_benefit_pro_rata_ratio_amount(sal_struct, component_max):
@@ -214,16 +212,16 @@
benefit_amount = component_max
return benefit_amount
-def get_benefit_amount(application, struct_row, payroll_period_days, payment_days):
+def get_benefit_amount(application, struct_row, period_factor, period_length):
amount = 0
for employee_benefit in application.employee_benefits:
if employee_benefit.earning_component == struct_row.salary_component:
- amount += get_amount(payroll_period_days, employee_benefit.amount, payment_days)
+ amount += get_amount(period_factor, employee_benefit.amount, period_length)
return amount if amount > 0 else False
-def get_amount(payroll_period_days, amount, payment_days):
- amount_per_day = amount / payroll_period_days
- total_amount = amount_per_day * payment_days
+def get_amount(period_factor, amount, period_length):
+ amount_per_day = amount / period_factor
+ total_amount = amount_per_day * period_length
return total_amount
def get_earning_components(doctype, txt, searchfield, start, page_len, filters):
diff --git a/erpnext/hr/doctype/salary_detail/salary_detail.json b/erpnext/hr/doctype/salary_detail/salary_detail.json
index cca3a87..d8775f5 100644
--- a/erpnext/hr/doctype/salary_detail/salary_detail.json
+++ b/erpnext/hr/doctype/salary_detail/salary_detail.json
@@ -286,6 +286,40 @@
"bold": 0,
"collapsible": 0,
"columns": 0,
+ "depends_on": "",
+ "fetch_from": "salary_component.depends_on_lwp",
+ "fieldname": "depends_on_lwp",
+ "fieldtype": "Check",
+ "hidden": 0,
+ "ignore_user_permissions": 0,
+ "ignore_xss_filter": 0,
+ "in_filter": 0,
+ "in_global_search": 0,
+ "in_list_view": 0,
+ "in_standard_filter": 0,
+ "label": "Depends on Leave Without Pay",
+ "length": 0,
+ "no_copy": 0,
+ "permlevel": 0,
+ "precision": "",
+ "print_hide": 1,
+ "print_hide_if_no_value": 0,
+ "read_only": 1,
+ "remember_last_selected_value": 0,
+ "report_hide": 0,
+ "reqd": 0,
+ "search_index": 0,
+ "set_only_once": 0,
+ "translatable": 0,
+ "unique": 0
+ },
+ {
+ "allow_bulk_edit": 0,
+ "allow_in_quick_entry": 0,
+ "allow_on_submit": 0,
+ "bold": 0,
+ "collapsible": 0,
+ "columns": 0,
"depends_on": "eval:doc.is_flexible_benefit != 1",
"fieldname": "section_break_2",
"fieldtype": "Section Break",
@@ -456,39 +490,6 @@
"bold": 0,
"collapsible": 0,
"columns": 0,
- "depends_on": "",
- "fieldname": "depends_on_lwp",
- "fieldtype": "Check",
- "hidden": 0,
- "ignore_user_permissions": 0,
- "ignore_xss_filter": 0,
- "in_filter": 0,
- "in_global_search": 0,
- "in_list_view": 0,
- "in_standard_filter": 0,
- "label": "Depends on Leave Without Pay",
- "length": 0,
- "no_copy": 0,
- "permlevel": 0,
- "precision": "",
- "print_hide": 1,
- "print_hide_if_no_value": 0,
- "read_only": 0,
- "remember_last_selected_value": 0,
- "report_hide": 0,
- "reqd": 0,
- "search_index": 0,
- "set_only_once": 0,
- "translatable": 0,
- "unique": 0
- },
- {
- "allow_bulk_edit": 0,
- "allow_in_quick_entry": 0,
- "allow_on_submit": 0,
- "bold": 0,
- "collapsible": 0,
- "columns": 0,
"fieldname": "do_not_include_in_total",
"fieldtype": "Check",
"hidden": 0,
@@ -625,7 +626,7 @@
"issingle": 0,
"istable": 1,
"max_attachments": 0,
- "modified": "2018-06-22 12:31:55.516982",
+ "modified": "2018-06-22 15:54:36.993512",
"modified_by": "Administrator",
"module": "HR",
"name": "Salary Detail",
diff --git a/erpnext/hr/doctype/salary_slip/salary_slip.py b/erpnext/hr/doctype/salary_slip/salary_slip.py
index c8834b5..42b63b6 100644
--- a/erpnext/hr/doctype/salary_slip/salary_slip.py
+++ b/erpnext/hr/doctype/salary_slip/salary_slip.py
@@ -109,7 +109,7 @@
def add_employee_flexi_benefits(self, struct_row):
if frappe.db.get_value("Salary Component", struct_row.salary_component, "pay_against_benefit_claim") != 1:
benefit_component_amount = get_benefit_component_amount(self.employee, self.start_date, self.end_date, \
- struct_row, self._salary_structure_doc, self.payment_days, self.total_working_days, self.payroll_frequency)
+ struct_row, self._salary_structure_doc, self.total_working_days, self.payroll_frequency)
if benefit_component_amount:
self.update_component_row(struct_row, benefit_component_amount, "earnings")
else: