fix: Employee Transfer and Project Profitability test cases (#28633)
* fix: Employee Transfer testcases * fix: Project Profitability test case
This commit is contained in:
parent
aeb62af544
commit
d0f4f03b66
@ -2,7 +2,6 @@
|
||||
# See license.txt
|
||||
|
||||
import unittest
|
||||
from datetime import date
|
||||
|
||||
import frappe
|
||||
from frappe.utils import add_days, getdate
|
||||
@ -12,16 +11,14 @@ from erpnext.hr.doctype.employee.test_employee import make_employee
|
||||
|
||||
class TestEmployeeTransfer(unittest.TestCase):
|
||||
def setUp(self):
|
||||
make_employee("employee2@transfers.com")
|
||||
make_employee("employee3@transfers.com")
|
||||
create_company()
|
||||
create_employee()
|
||||
create_employee_transfer()
|
||||
|
||||
def tearDown(self):
|
||||
frappe.db.rollback()
|
||||
|
||||
def test_submit_before_transfer_date(self):
|
||||
make_employee("employee2@transfers.com")
|
||||
|
||||
transfer_obj = frappe.get_doc({
|
||||
"doctype": "Employee Transfer",
|
||||
"employee": frappe.get_value("Employee", {"user_id":"employee2@transfers.com"}, "name"),
|
||||
@ -43,6 +40,8 @@ class TestEmployeeTransfer(unittest.TestCase):
|
||||
self.assertEqual(transfer.docstatus, 1)
|
||||
|
||||
def test_new_employee_creation(self):
|
||||
make_employee("employee3@transfers.com")
|
||||
|
||||
transfer = frappe.get_doc({
|
||||
"doctype": "Employee Transfer",
|
||||
"employee": frappe.get_value("Employee", {"user_id":"employee3@transfers.com"}, "name"),
|
||||
@ -63,60 +62,51 @@ class TestEmployeeTransfer(unittest.TestCase):
|
||||
self.assertEqual(frappe.get_value("Employee", transfer.employee, "status"), "Left")
|
||||
|
||||
def test_employee_history(self):
|
||||
name = frappe.get_value("Employee", {"first_name": "John", "company": "Test Company"}, "name")
|
||||
doc = frappe.get_doc("Employee",name)
|
||||
employee = make_employee("employee4@transfers.com",
|
||||
company="Test Company",
|
||||
date_of_birth=getdate("30-09-1980"),
|
||||
date_of_joining=getdate("01-10-2021"),
|
||||
department="Accounts - TC",
|
||||
designation="Accountant"
|
||||
)
|
||||
transfer = create_employee_transfer(employee)
|
||||
|
||||
count = 0
|
||||
department = ["Accounts - TC", "Management - TC"]
|
||||
designation = ["Accountant", "Manager"]
|
||||
dt = [getdate("01-10-2021"), date.today()]
|
||||
dt = [getdate("01-10-2021"), getdate()]
|
||||
|
||||
for data in doc.internal_work_history:
|
||||
employee = frappe.get_doc("Employee", employee)
|
||||
for data in employee.internal_work_history:
|
||||
self.assertEqual(data.department, department[count])
|
||||
self.assertEqual(data.designation, designation[count])
|
||||
self.assertEqual(data.from_date, dt[count])
|
||||
count = count + 1
|
||||
|
||||
data = frappe.db.get_list("Employee Transfer", filters={"employee":name}, fields=["*"])
|
||||
doc = frappe.get_doc("Employee Transfer", data[0]["name"])
|
||||
doc.cancel()
|
||||
employee_doc = frappe.get_doc("Employee",name)
|
||||
transfer.cancel()
|
||||
employee.reload()
|
||||
|
||||
for data in employee_doc.internal_work_history:
|
||||
for data in employee.internal_work_history:
|
||||
self.assertEqual(data.designation, designation[0])
|
||||
self.assertEqual(data.department, department[0])
|
||||
self.assertEqual(data.from_date, dt[0])
|
||||
|
||||
def create_employee():
|
||||
doc = frappe.get_doc({
|
||||
"doctype": "Employee",
|
||||
"first_name": "John",
|
||||
"company": "Test Company",
|
||||
"gender": "Male",
|
||||
"date_of_birth": getdate("30-09-1980"),
|
||||
"date_of_joining": getdate("01-10-2021"),
|
||||
"department": "Accounts - TC",
|
||||
"designation": "Accountant"
|
||||
})
|
||||
|
||||
doc.save()
|
||||
|
||||
def create_company():
|
||||
exists = frappe.db.exists("Company", "Test Company")
|
||||
if not exists:
|
||||
doc = frappe.get_doc({
|
||||
"doctype": "Company",
|
||||
"company_name": "Test Company",
|
||||
"default_currency": "INR",
|
||||
"country": "India"
|
||||
})
|
||||
if not frappe.db.exists("Company", "Test Company"):
|
||||
frappe.get_doc({
|
||||
"doctype": "Company",
|
||||
"company_name": "Test Company",
|
||||
"default_currency": "INR",
|
||||
"country": "India"
|
||||
}).insert()
|
||||
|
||||
doc.save()
|
||||
|
||||
def create_employee_transfer():
|
||||
def create_employee_transfer(employee):
|
||||
doc = frappe.get_doc({
|
||||
"doctype": "Employee Transfer",
|
||||
"employee": frappe.get_value("Employee", {"first_name": "John", "company": "Test Company"}, "name"),
|
||||
"transfer_date": date.today(),
|
||||
"employee": employee,
|
||||
"transfer_date": getdate(),
|
||||
"transfer_details": [
|
||||
{
|
||||
"property": "Designation",
|
||||
@ -134,4 +124,6 @@ def create_employee_transfer():
|
||||
})
|
||||
|
||||
doc.save()
|
||||
doc.submit()
|
||||
doc.submit()
|
||||
|
||||
return doc
|
@ -1,7 +1,7 @@
|
||||
import unittest
|
||||
|
||||
import frappe
|
||||
from frappe.utils import add_days, getdate, nowdate
|
||||
from frappe.utils import add_days, getdate
|
||||
|
||||
from erpnext.hr.doctype.employee.test_employee import make_employee
|
||||
from erpnext.projects.doctype.timesheet.test_timesheet import (
|
||||
@ -13,21 +13,26 @@ from erpnext.projects.report.project_profitability.project_profitability import
|
||||
|
||||
|
||||
class TestProjectProfitability(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
frappe.db.sql('delete from `tabTimesheet`')
|
||||
emp = make_employee('test_employee_9@salary.com', company='_Test Company')
|
||||
|
||||
if not frappe.db.exists('Salary Component', 'Timesheet Component'):
|
||||
frappe.get_doc({'doctype': 'Salary Component', 'salary_component': 'Timesheet Component'}).insert()
|
||||
|
||||
make_salary_structure_for_timesheet(emp, company='_Test Company')
|
||||
self.timesheet = make_timesheet(emp, simulate = True, is_billable=1)
|
||||
date = getdate()
|
||||
|
||||
self.timesheet = make_timesheet(emp, is_billable=1)
|
||||
self.salary_slip = make_salary_slip(self.timesheet.name)
|
||||
holidays = self.salary_slip.get_holidays_for_employee(nowdate(), nowdate())
|
||||
|
||||
holidays = self.salary_slip.get_holidays_for_employee(date, date)
|
||||
if holidays:
|
||||
frappe.db.set_value('Payroll Settings', None, 'include_holidays_in_total_working_days', 1)
|
||||
|
||||
self.salary_slip.submit()
|
||||
self.sales_invoice = make_sales_invoice(self.timesheet.name, '_Test Item', '_Test Customer')
|
||||
self.sales_invoice.due_date = nowdate()
|
||||
self.sales_invoice.due_date = date
|
||||
self.sales_invoice.submit()
|
||||
|
||||
frappe.db.set_value('HR Settings', None, 'standard_working_hours', 8)
|
||||
@ -63,6 +68,4 @@ class TestProjectProfitability(unittest.TestCase):
|
||||
self.assertEqual(fractional_cost, row.fractional_cost)
|
||||
|
||||
def tearDown(self):
|
||||
frappe.get_doc("Sales Invoice", self.sales_invoice.name).cancel()
|
||||
frappe.get_doc("Salary Slip", self.salary_slip.name).cancel()
|
||||
frappe.get_doc("Timesheet", self.timesheet.name).cancel()
|
||||
frappe.db.rollback()
|
||||
|
Loading…
x
Reference in New Issue
Block a user