mirror of
https://github.com/frappe/erpnext.git
synced 2026-04-25 01:28:29 +00:00
refactor(test): make timesheet and activity type deterministic
This commit is contained in:
@@ -13,6 +13,7 @@ class TestActivityCost(ERPNextTestSuite):
|
||||
super().setUpClass()
|
||||
# TODO: only 1 employee is required
|
||||
cls.make_employees()
|
||||
cls.make_activity_type()
|
||||
|
||||
def test_duplication(self):
|
||||
frappe.db.sql("delete from `tabActivity Cost`")
|
||||
@@ -21,7 +22,7 @@ class TestActivityCost(ERPNextTestSuite):
|
||||
{
|
||||
"employee": self.employees[0].name,
|
||||
"employee_name": self.employees[0].first_name,
|
||||
"activity_type": "_Test Activity Type 1",
|
||||
"activity_type": self.activity_type[1].name,
|
||||
"billing_rate": 100,
|
||||
"costing_rate": 50,
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ class TestTimesheet(ERPNextTestSuite):
|
||||
def setUpClass(cls):
|
||||
super().setUpClass()
|
||||
cls.make_projects()
|
||||
cls.make_activity_type()
|
||||
|
||||
def setUp(self):
|
||||
frappe.db.delete("Timesheet")
|
||||
@@ -101,7 +102,7 @@ class TestTimesheet(ERPNextTestSuite):
|
||||
self.assertEqual(timesheet.total_billable_amount, 0)
|
||||
|
||||
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)
|
||||
sales_invoice = make_sales_invoice(timesheet.name, "_Test Item", "_Test Customer", currency="INR")
|
||||
@@ -286,7 +287,7 @@ class TestTimesheet(ERPNextTestSuite):
|
||||
This test ensures Timesheet status is recalculated correctly
|
||||
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_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
|
||||
def set_user(self, user: str):
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user