mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-02 19:59:12 +00:00
refactor(test): make timesheet and activity type deterministic
This commit is contained in:
@@ -15,6 +15,7 @@ class TestActivityCost(ERPNextTestSuite):
|
|||||||
super().setUpClass()
|
super().setUpClass()
|
||||||
# TODO: only 1 employee is required
|
# TODO: only 1 employee is required
|
||||||
cls.make_employees()
|
cls.make_employees()
|
||||||
|
cls.make_activity_type()
|
||||||
|
|
||||||
def test_duplication(self):
|
def test_duplication(self):
|
||||||
frappe.db.sql("delete from `tabActivity Cost`")
|
frappe.db.sql("delete from `tabActivity Cost`")
|
||||||
@@ -23,7 +24,7 @@ class TestActivityCost(ERPNextTestSuite):
|
|||||||
{
|
{
|
||||||
"employee": self.employees[0].name,
|
"employee": self.employees[0].name,
|
||||||
"employee_name": self.employees[0].first_name,
|
"employee_name": self.employees[0].first_name,
|
||||||
"activity_type": "_Test Activity Type 1",
|
"activity_type": self.activity_type[1].name,
|
||||||
"billing_rate": 100,
|
"billing_rate": 100,
|
||||||
"costing_rate": 50,
|
"costing_rate": 50,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ class TestTimesheet(ERPNextTestSuite):
|
|||||||
def setUpClass(cls):
|
def setUpClass(cls):
|
||||||
super().setUpClass()
|
super().setUpClass()
|
||||||
cls.make_projects()
|
cls.make_projects()
|
||||||
|
cls.make_activity_type()
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
frappe.db.delete("Timesheet")
|
frappe.db.delete("Timesheet")
|
||||||
@@ -102,7 +103,7 @@ class TestTimesheet(ERPNextTestSuite):
|
|||||||
self.assertEqual(timesheet.total_billable_amount, 0)
|
self.assertEqual(timesheet.total_billable_amount, 0)
|
||||||
|
|
||||||
def test_sales_invoice_from_timesheet(self):
|
def test_sales_invoice_from_timesheet(self):
|
||||||
emp = make_employee("test_employee_6@salary.com")
|
emp = make_employee("test_employee_6@salary.com", company=self.companies[0].name)
|
||||||
|
|
||||||
timesheet = make_timesheet(emp, simulate=True, is_billable=1)
|
timesheet = make_timesheet(emp, simulate=True, is_billable=1)
|
||||||
sales_invoice = make_sales_invoice(timesheet.name, "_Test Item", "_Test Customer", currency="INR")
|
sales_invoice = make_sales_invoice(timesheet.name, "_Test Item", "_Test Customer", currency="INR")
|
||||||
@@ -287,7 +288,7 @@ class TestTimesheet(ERPNextTestSuite):
|
|||||||
This test ensures Timesheet status is recalculated correctly
|
This test ensures Timesheet status is recalculated correctly
|
||||||
across billing and return lifecycle events.
|
across billing and return lifecycle events.
|
||||||
"""
|
"""
|
||||||
emp = make_employee("test_employee_6@salary.com")
|
emp = make_employee("test_employee_6@salary.com", company=self.companies[0].name)
|
||||||
|
|
||||||
timesheet = make_timesheet(emp, simulate=True, is_billable=1, do_not_submit=True)
|
timesheet = make_timesheet(emp, simulate=True, is_billable=1, do_not_submit=True)
|
||||||
timesheet_detail = timesheet.append("time_logs", {})
|
timesheet_detail = timesheet.append("time_logs", {})
|
||||||
|
|||||||
@@ -2616,6 +2616,29 @@ class ERPNextTestSuite(unittest.TestCase):
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def make_activity_type(cls):
|
||||||
|
records = [
|
||||||
|
{
|
||||||
|
"doctype": "Activity Type",
|
||||||
|
"name": "_Test Activity Type",
|
||||||
|
"activity_type": "_Test Activity Type",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"doctype": "Activity Type",
|
||||||
|
"name": "_Test Activity Type 1",
|
||||||
|
"activity_type": "_Test Activity Type 1",
|
||||||
|
},
|
||||||
|
]
|
||||||
|
cls.activity_type = []
|
||||||
|
for x in records:
|
||||||
|
if not frappe.db.exists("Activity Type", {"activity_type": x.get("activity_type")}):
|
||||||
|
cls.activity_type.append(frappe.get_doc(x).insert())
|
||||||
|
else:
|
||||||
|
cls.activity_type.append(
|
||||||
|
frappe.get_doc("Activity Type", {"activity_type": x.get("activity_type")})
|
||||||
|
)
|
||||||
|
|
||||||
@contextmanager
|
@contextmanager
|
||||||
def set_user(self, user: str):
|
def set_user(self, user: str):
|
||||||
try:
|
try:
|
||||||
|
|||||||
Reference in New Issue
Block a user