From 779f8ebbb3beea77cfbffe8c77824db43f6a7e0b Mon Sep 17 00:00:00 2001 From: Jamsheer Date: Mon, 14 May 2018 12:05:11 +0530 Subject: [PATCH] Employee Benefit Application - get max benefit --- .../employee_benefit_application.py | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) 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 f409a135fc..061eb12f72 100644 --- a/erpnext/hr/doctype/employee_benefit_application/employee_benefit_application.py +++ b/erpnext/hr/doctype/employee_benefit_application/employee_benefit_application.py @@ -5,6 +5,7 @@ from __future__ import unicode_literals import frappe from frappe import _ +from frappe.utils import nowdate from frappe.model.document import Document class EmployeeBenefitApplication(Document): @@ -22,3 +23,26 @@ class EmployeeBenefitApplication(Document): ) if application: frappe.throw(_("Employee {0} already submited an apllication {1} for the payroll period {2}").format(self.employee, application, self.payroll_period)) + + def get_max_benefits(self): + sal_struct = get_assigned_salary_sturecture(self.employee, self.date) + if sal_struct: + return frappe.db.get_value("Salary Structure", sal_struct[0][0], "max_benefits") + + +@frappe.whitelist() +def get_assigned_salary_sturecture(employee, _date): + if not _date: + _date = nowdate() + salary_structure = frappe.db.sql(""" + select salary_structure from `tabSalary Structure Assignment` + where employee=%(employee)s + and docstatus = 1 + and ( + (%(_date)s between from_date and ifnull(to_date, '2199-12-31')) + )""", { + 'employee': employee, + '_date': _date, + }) + if salary_structure: + return salary_structure