diff --git a/erpnext/hr/doctype/additional_salary/additional_salary.py b/erpnext/hr/doctype/additional_salary/additional_salary.py index c37c1b4d2d..d1b602d243 100644 --- a/erpnext/hr/doctype/additional_salary/additional_salary.py +++ b/erpnext/hr/doctype/additional_salary/additional_salary.py @@ -54,11 +54,11 @@ def get_additional_salary_component(employee, start_date, end_date, component_ty from `tabAdditional Salary` where employee=%(employee)s and docstatus = 1 - and (payroll_date between %(from_date)s and %(to_date)s) - or ( - (from_date between %(from_date)s and %(to_date)s) - or(to_date between %(from_date)s and %(to_date)s) - ) + and ( + payroll_date between %(from_date)s and %(to_date)s + or + from_date <= %(to_date)s and to_date >= %(to_date)s + ) and type = %(component_type)s group by salary_component, overwrite_salary_structure_amount order by salary_component, overwrite_salary_structure_amount diff --git a/erpnext/hr/doctype/additional_salary/test_additional_salary.py b/erpnext/hr/doctype/additional_salary/test_additional_salary.py index 949ba20335..ebe6b20d81 100644 --- a/erpnext/hr/doctype/additional_salary/test_additional_salary.py +++ b/erpnext/hr/doctype/additional_salary/test_additional_salary.py @@ -3,6 +3,45 @@ # See license.txt from __future__ import unicode_literals import unittest +import frappe, erpnext +from frappe.utils import nowdate, add_days +from erpnext.hr.doctype.employee.test_employee import make_employee +from erpnext.hr.doctype.salary_component.test_salary_component import create_salary_component +from erpnext.hr.doctype.salary_slip.test_salary_slip import make_employee_salary_slip + class TestAdditionalSalary(unittest.TestCase): - pass + + def setUp(self): + from erpnext.hr.doctype.salary_slip.test_salary_slip import TestSalarySlip + TestSalarySlip().setUp() + + def test_recurring_additional_salary(self): + emp_id = make_employee("test_additional@salary.com") + frappe.db.set_value("Employee", emp_id, "relieving_date", add_days(nowdate(), 1800)) + add_sal = get_additional_salary(emp_id) + + ss = make_employee_salary_slip("test_additional@salary.com", "Monthly") + for earning in ss.earnings: + if earning.salary_component == "Recurring Salary Component": + amount = earning.amount + salary_component = earning.salary_component + + self.assertEqual(amount, add_sal.amount) + self.assertEqual(salary_component, add_sal.salary_component) + + + +def get_additional_salary(emp_id): + create_salary_component("Recurring Salary Component") + add_sal = frappe.new_doc("Additional Salary") + add_sal.employee = emp_id + add_sal.salary_component = "Recurring Salary Component" + add_sal.is_recurring = 1 + add_sal.from_date = add_days(nowdate(), -50) + add_sal.to_date = add_days(nowdate(), 180) + add_sal.amount = 5000 + add_sal.save() + add_sal.submit() + + return add_sal diff --git a/erpnext/hr/doctype/employee/test_employee.py b/erpnext/hr/doctype/employee/test_employee.py index d3410de2eb..906386db11 100644 --- a/erpnext/hr/doctype/employee/test_employee.py +++ b/erpnext/hr/doctype/employee/test_employee.py @@ -51,7 +51,7 @@ def make_employee(user, company=None): "doctype": "User", "email": user, "first_name": user, - "new_password": "password", + "new_password": "qwerty123@12435", "roles": [{"doctype": "Has Role", "role": "Employee"}] }).insert()