From 0780fd1e0ba2da13905a2ab3fca4a780444d5e0b Mon Sep 17 00:00:00 2001 From: anoop Date: Fri, 11 May 2018 20:15:28 +0530 Subject: [PATCH] helper method to get employees assigned salary structure --- .../salary_structure_assignment.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/erpnext/hr/doctype/salary_structure_assignment/salary_structure_assignment.py b/erpnext/hr/doctype/salary_structure_assignment/salary_structure_assignment.py index ee2920be2ce..26e7fce9fe5 100644 --- a/erpnext/hr/doctype/salary_structure_assignment/salary_structure_assignment.py +++ b/erpnext/hr/doctype/salary_structure_assignment/salary_structure_assignment.py @@ -55,3 +55,20 @@ class SalaryStructureAssignment(Document): if assignment: frappe.throw(_("Active Salary Structure Assignment {0} found for employee {1} for the given dates").format(assignment[0][0], self.employee)) + +def get_assigned_salary_structure(employee, on_date): + if not employee or not on_date: + return None + + salary_structure = frappe.db.sql(""" + select salary_structure from `tabSalary Structure Assignment` + where employee=%(employee)s + and docstatus = 1 + and ( + (%(on_date)s between from_date and ifnull(to_date, '2199-12-31')) + )""", { + 'employee': employee, + 'on_date': on_date, + }) + + return salary_structure[0][0] if salary_structure else None