mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-07 07:02:54 +00:00
fix: tests
This commit is contained in:
@@ -167,15 +167,11 @@ class EmployeeHoursReport:
|
|||||||
|
|
||||||
def set_employee_department_and_name(self):
|
def set_employee_department_and_name(self):
|
||||||
for emp in self.stats_by_employee:
|
for emp in self.stats_by_employee:
|
||||||
emp_name = frappe.db.get_value(
|
|
||||||
'Employee', emp, 'employee_name'
|
|
||||||
)
|
|
||||||
emp_dept = frappe.db.get_value(
|
emp_dept = frappe.db.get_value(
|
||||||
'Employee', emp, 'department'
|
'Employee', emp, 'department'
|
||||||
)
|
)
|
||||||
|
|
||||||
self.stats_by_employee[emp]['department'] = emp_dept
|
self.stats_by_employee[emp]['department'] = emp_dept
|
||||||
self.stats_by_employee[emp]['employee_name'] = emp_name
|
|
||||||
|
|
||||||
def calculate_utilizations(self):
|
def calculate_utilizations(self):
|
||||||
TOTAL_HOURS = flt(self.standard_working_hours * self.day_span, 2)
|
TOTAL_HOURS = flt(self.standard_working_hours * self.day_span, 2)
|
||||||
|
|||||||
@@ -20,6 +20,8 @@ class TestEmployeeUtilization(unittest.TestCase):
|
|||||||
# Create test timesheets
|
# Create test timesheets
|
||||||
cls.create_test_timesheets()
|
cls.create_test_timesheets()
|
||||||
|
|
||||||
|
frappe.db.set_value("HR Settings", "HR Settings", "standard_working_hours", 9)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def create_test_timesheets(cls):
|
def create_test_timesheets(cls):
|
||||||
timesheet1 = frappe.new_doc("Timesheet")
|
timesheet1 = frappe.new_doc("Timesheet")
|
||||||
@@ -51,7 +53,7 @@ class TestEmployeeUtilization(unittest.TestCase):
|
|||||||
})
|
})
|
||||||
|
|
||||||
timesheet2.save()
|
timesheet2.save()
|
||||||
timesheet2.submit()
|
timesheet2.submit()
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def tearDownClass(cls):
|
def tearDownClass(cls):
|
||||||
@@ -59,8 +61,8 @@ class TestEmployeeUtilization(unittest.TestCase):
|
|||||||
frappe.db.sql("""
|
frappe.db.sql("""
|
||||||
DELETE FROM `tabTimesheet Detail`
|
DELETE FROM `tabTimesheet Detail`
|
||||||
WHERE parent IN (
|
WHERE parent IN (
|
||||||
SELECT name
|
SELECT name
|
||||||
FROM `tabTimesheet`
|
FROM `tabTimesheet`
|
||||||
WHERE company = '_Test Company'
|
WHERE company = '_Test Company'
|
||||||
)
|
)
|
||||||
""")
|
""")
|
||||||
@@ -72,14 +74,14 @@ class TestEmployeeUtilization(unittest.TestCase):
|
|||||||
filters = {
|
filters = {
|
||||||
"company": "_Test Company",
|
"company": "_Test Company",
|
||||||
"from_date": "2021-04-01",
|
"from_date": "2021-04-01",
|
||||||
"to_date": "2021-04-03"
|
"to_date": "2021-04-03"
|
||||||
}
|
}
|
||||||
|
|
||||||
report = execute(filters)
|
report = execute(filters)
|
||||||
|
|
||||||
expected_data = self.get_expected_data_for_test_employees()
|
expected_data = self.get_expected_data_for_test_employees()
|
||||||
self.assertEqual(report[1], expected_data)
|
self.assertEqual(report[1], expected_data)
|
||||||
|
|
||||||
def test_utilization_report_for_single_employee(self):
|
def test_utilization_report_for_single_employee(self):
|
||||||
filters = {
|
filters = {
|
||||||
"company": "_Test Company",
|
"company": "_Test Company",
|
||||||
@@ -93,14 +95,14 @@ class TestEmployeeUtilization(unittest.TestCase):
|
|||||||
emp1_data = frappe.get_doc('Employee', self.test_emp1)
|
emp1_data = frappe.get_doc('Employee', self.test_emp1)
|
||||||
expected_data = [
|
expected_data = [
|
||||||
{
|
{
|
||||||
'employee': self.test_emp1,
|
'employee': self.test_emp1,
|
||||||
'employee_name': emp1_data.employee_name,
|
'billed_hours': 5.0,
|
||||||
|
'non_billed_hours': 0.0,
|
||||||
'department': emp1_data.department,
|
'department': emp1_data.department,
|
||||||
'billed_hours': 5.0,
|
'total_hours': 18.0,
|
||||||
'non_billed_hours': 0.0,
|
'untracked_hours': 13.0,
|
||||||
'total_hours': 18.0,
|
'per_util': 27.78,
|
||||||
'untracked_hours': 13.0,
|
'per_util_billed_only': 27.78
|
||||||
'per_util': 27.78
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -115,18 +117,18 @@ class TestEmployeeUtilization(unittest.TestCase):
|
|||||||
}
|
}
|
||||||
|
|
||||||
report = execute(filters)
|
report = execute(filters)
|
||||||
|
|
||||||
emp2_data = frappe.get_doc('Employee', self.test_emp2)
|
emp2_data = frappe.get_doc('Employee', self.test_emp2)
|
||||||
expected_data = [
|
expected_data = [
|
||||||
{
|
{
|
||||||
'employee': self.test_emp2,
|
'employee': self.test_emp2,
|
||||||
'employee_name': emp2_data.employee_name,
|
'billed_hours': 0.0,
|
||||||
|
'non_billed_hours': 10.0,
|
||||||
'department': emp2_data.department,
|
'department': emp2_data.department,
|
||||||
'billed_hours': 0.0,
|
'total_hours': 18.0,
|
||||||
'non_billed_hours': 10.0,
|
'untracked_hours': 8.0,
|
||||||
'total_hours': 18.0,
|
'per_util': 55.56,
|
||||||
'untracked_hours': 8.0,
|
'per_util_billed_only': 0.0
|
||||||
'per_util': 55.56
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -155,7 +157,7 @@ class TestEmployeeUtilization(unittest.TestCase):
|
|||||||
|
|
||||||
report = execute(filters)
|
report = execute(filters)
|
||||||
summary = report[4]
|
summary = report[4]
|
||||||
expected_summary_values = ['41.67%', 5.0, 10.0, 21.0]
|
expected_summary_values = ['41.67%', '13.89%', 5.0, 10.0]
|
||||||
|
|
||||||
self.assertEqual(len(summary), 4)
|
self.assertEqual(len(summary), 4)
|
||||||
|
|
||||||
@@ -167,26 +169,26 @@ class TestEmployeeUtilization(unittest.TestCase):
|
|||||||
def get_expected_data_for_test_employees(self):
|
def get_expected_data_for_test_employees(self):
|
||||||
emp1_data = frappe.get_doc('Employee', self.test_emp1)
|
emp1_data = frappe.get_doc('Employee', self.test_emp1)
|
||||||
emp2_data = frappe.get_doc('Employee', self.test_emp2)
|
emp2_data = frappe.get_doc('Employee', self.test_emp2)
|
||||||
|
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
'employee': self.test_emp2,
|
'employee': self.test_emp2,
|
||||||
'employee_name': emp2_data.employee_name,
|
'billed_hours': 0.0,
|
||||||
'department': emp2_data.department,
|
'non_billed_hours': 10.0,
|
||||||
'billed_hours': 0.0,
|
'department': emp2_data.department,
|
||||||
'non_billed_hours': 10.0,
|
'total_hours': 18.0,
|
||||||
'total_hours': 18.0,
|
'untracked_hours': 8.0,
|
||||||
'untracked_hours': 8.0,
|
'per_util': 55.56,
|
||||||
'per_util': 55.56
|
'per_util_billed_only': 0.0
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'employee': self.test_emp1,
|
'employee': self.test_emp1,
|
||||||
'employee_name': emp1_data.employee_name,
|
'billed_hours': 5.0,
|
||||||
'department': emp1_data.department,
|
'non_billed_hours': 0.0,
|
||||||
'billed_hours': 5.0,
|
'department': emp1_data.department,
|
||||||
'non_billed_hours': 0.0,
|
'total_hours': 18.0,
|
||||||
'total_hours': 18.0,
|
'untracked_hours': 13.0,
|
||||||
'untracked_hours': 13.0,
|
'per_util': 27.78,
|
||||||
'per_util': 27.78
|
'per_util_billed_only': 27.78
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@@ -3,7 +3,7 @@ import unittest
|
|||||||
import frappe
|
import frappe
|
||||||
from frappe.utils import getdate, nowdate
|
from frappe.utils import getdate, nowdate
|
||||||
from erpnext.hr.doctype.employee.test_employee import make_employee
|
from erpnext.hr.doctype.employee.test_employee import make_employee
|
||||||
from erpnext.projects.doctype.timesheet.test_timesheet import make_salary_structure_for_timesheet, make_timesheet
|
from erpnext.projects.doctype.timesheet.test_timesheet import make_salary_structure_for_timesheet, make_timesheet
|
||||||
from erpnext.projects.doctype.timesheet.timesheet import make_salary_slip, make_sales_invoice
|
from erpnext.projects.doctype.timesheet.timesheet import make_salary_slip, make_sales_invoice
|
||||||
from erpnext.projects.report.project_profitability.project_profitability import execute
|
from erpnext.projects.report.project_profitability.project_profitability import execute
|
||||||
|
|
||||||
@@ -21,6 +21,8 @@ class TestProjectProfitability(unittest.TestCase):
|
|||||||
self.sales_invoice.due_date = nowdate()
|
self.sales_invoice.due_date = nowdate()
|
||||||
self.sales_invoice.submit()
|
self.sales_invoice.submit()
|
||||||
|
|
||||||
|
frappe.db.set_value("HR Settings", "HR Settings", "standard_working_hours", 8)
|
||||||
|
|
||||||
def test_project_profitability(self):
|
def test_project_profitability(self):
|
||||||
filters = {
|
filters = {
|
||||||
'company': '_Test Company',
|
'company': '_Test Company',
|
||||||
@@ -43,7 +45,7 @@ class TestProjectProfitability(unittest.TestCase):
|
|||||||
standard_working_hours = frappe.db.get_single_value("HR Settings", "standard_working_hours")
|
standard_working_hours = frappe.db.get_single_value("HR Settings", "standard_working_hours")
|
||||||
utilization = timesheet.total_billed_hours/(self.salary_slip.total_working_days * standard_working_hours)
|
utilization = timesheet.total_billed_hours/(self.salary_slip.total_working_days * standard_working_hours)
|
||||||
self.assertEqual(utilization, row.utilization)
|
self.assertEqual(utilization, row.utilization)
|
||||||
|
|
||||||
profit = self.sales_invoice.base_grand_total - self.salary_slip.base_gross_pay * utilization
|
profit = self.sales_invoice.base_grand_total - self.salary_slip.base_gross_pay * utilization
|
||||||
self.assertEqual(profit, row.profit)
|
self.assertEqual(profit, row.profit)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user