diff --git a/erpnext/hr/doctype/payroll_entry/test_payroll_entry.py b/erpnext/hr/doctype/payroll_entry/test_payroll_entry.py index acf339d435..9cf49790de 100644 --- a/erpnext/hr/doctype/payroll_entry/test_payroll_entry.py +++ b/erpnext/hr/doctype/payroll_entry/test_payroll_entry.py @@ -73,7 +73,7 @@ class TestPayrollEntry(unittest.TestCase): loan.repay_from_salary = 1 loan.submit() salary_structure = "Test Salary Structure for Loan" - salary_structure = make_salary_structure(salary_structure, "Monthly", employee_doc.name) + make_salary_structure(salary_structure, "Monthly", employee_doc.name) dates = get_start_end_dates('Monthly', nowdate()) make_payroll_entry(start_date=dates.start_date, diff --git a/erpnext/hr/doctype/salary_slip/test_salary_slip.py b/erpnext/hr/doctype/salary_slip/test_salary_slip.py index 6cbfa1c3e5..b856487b8d 100644 --- a/erpnext/hr/doctype/salary_slip/test_salary_slip.py +++ b/erpnext/hr/doctype/salary_slip/test_salary_slip.py @@ -198,11 +198,11 @@ def make_employee_salary_slip(user, payroll_frequency, salary_structure=None): if not salary_structure: salary_structure = payroll_frequency + " Salary Structure Test for Salary Slip" employee = frappe.db.get_value("Employee", {"user_id": user}) - salary_structure = make_salary_structure(salary_structure, payroll_frequency, employee) + salary_structure_doc = make_salary_structure(salary_structure, payroll_frequency, employee) salary_slip = frappe.db.get_value("Salary Slip", {"employee": frappe.db.get_value("Employee", {"user_id": user})}) if not salary_slip: - salary_slip = make_salary_slip(salary_structure, employee = employee) + salary_slip = make_salary_slip(salary_structure_doc.name, employee = employee) salary_slip.employee_name = frappe.get_value("Employee", {"name":frappe.db.get_value("Employee", {"user_id": user})}, "employee_name") salary_slip.payroll_frequency = payroll_frequency salary_slip.posting_date = nowdate() diff --git a/erpnext/hr/doctype/salary_structure/test_salary_structure.py b/erpnext/hr/doctype/salary_structure/test_salary_structure.py index da55306d58..c15a8a23c9 100644 --- a/erpnext/hr/doctype/salary_structure/test_salary_structure.py +++ b/erpnext/hr/doctype/salary_structure/test_salary_structure.py @@ -53,8 +53,7 @@ class TestSalaryStructure(unittest.TestCase): self.assertEqual(sal_slip.get("net_pay"), 30500) def test_whitespaces_in_formula_conditions_fields(self): - make_salary_structure("Salary Structure Sample", "Monthly") - salary_structure = frappe.get_doc("Salary Structure", "Salary Structure Sample") + salary_structure = make_salary_structure("Salary Structure Sample", "Monthly", dont_submit=True) for row in salary_structure.earnings: row.formula = "\n%s\n\n"%row.formula @@ -73,7 +72,7 @@ class TestSalaryStructure(unittest.TestCase): self.assertFalse(("\n" in row.formula) or ("\n" in row.condition)) -def make_salary_structure(salary_structure, payroll_frequency, employee=None): +def make_salary_structure(salary_structure, payroll_frequency, employee=None, dont_submit=False): if not frappe.db.exists('Salary Structure', salary_structure): salary_structure_doc = frappe.get_doc({ "doctype": "Salary Structure", @@ -84,12 +83,16 @@ def make_salary_structure(salary_structure, payroll_frequency, employee=None): "payroll_frequency": payroll_frequency, "payment_account": get_random("Account") }).insert() - salary_structure_doc.submit() + if not dont_submit: + salary_structure_doc.submit() + else: + salary_structure_doc = frappe.get_doc("Salary Structure", salary_structure) if employee and not frappe.db.get_value("Salary Structure Assignment", - {'employee':employee, 'docstatus': 1}): + {'employee':employee, 'docstatus': 1}) and salary_structure_doc.docstatus==1: create_salary_structure_assignment(employee, salary_structure) - return salary_structure + + return salary_structure_doc def create_salary_structure_assignment(employee, salary_structure): salary_structure_assignment = frappe.new_doc("Salary Structure Assignment") diff --git a/erpnext/projects/doctype/timesheet/test_timesheet.py b/erpnext/projects/doctype/timesheet/test_timesheet.py index 5dac24cfcd..1f274dbf55 100644 --- a/erpnext/projects/doctype/timesheet/test_timesheet.py +++ b/erpnext/projects/doctype/timesheet/test_timesheet.py @@ -11,6 +11,8 @@ from frappe.utils import now_datetime, nowdate, add_days, add_months from erpnext.projects.doctype.timesheet.timesheet import OverlapError from erpnext.projects.doctype.timesheet.timesheet import make_salary_slip, make_sales_invoice from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice +from erpnext.hr.doctype.salary_structure.test_salary_structure \ + import make_salary_structure, create_salary_structure_assignment class TestTimesheet(unittest.TestCase): @@ -131,13 +133,16 @@ def make_salary_structure_for_timesheet(employee): salary_structure_name = "Timesheet Salary Structure Test" frequency = "Monthly" - from erpnext.hr.doctype.salary_structure.test_salary_structure import make_salary_structure - salary_structure = make_salary_structure(salary_structure_name, frequency, employee) - salary_structure = frappe.get_doc("Salary Structure", salary_structure) + salary_structure = make_salary_structure(salary_structure_name, frequency, dont_submit=True) salary_structure.salary_component = "Timesheet Component" salary_structure.salary_slip_based_on_timesheet = 1 salary_structure.hour_rate = 50.0 salary_structure.save() + salary_structure.submit() + + if not frappe.db.get_value("Salary Structure Assignment", + {'employee':employee, 'docstatus': 1}): + create_salary_structure_assignment(employee, salary_structure.name) return salary_structure