From 524118e108d1d1b5876a09cfa0c853a68fff7e3c Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Thu, 13 Nov 2025 13:55:12 +0530 Subject: [PATCH] refactor(test): make timesheet and activity type deterministic --- .../activity_cost/test_activity_cost.py | 3 ++- .../doctype/timesheet/test_timesheet.py | 5 ++-- erpnext/tests/utils.py | 23 +++++++++++++++++++ 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/erpnext/projects/doctype/activity_cost/test_activity_cost.py b/erpnext/projects/doctype/activity_cost/test_activity_cost.py index ffac534a3f6..a4f20fe7f06 100644 --- a/erpnext/projects/doctype/activity_cost/test_activity_cost.py +++ b/erpnext/projects/doctype/activity_cost/test_activity_cost.py @@ -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, } diff --git a/erpnext/projects/doctype/timesheet/test_timesheet.py b/erpnext/projects/doctype/timesheet/test_timesheet.py index 5fd1573f39e..27536e59eda 100644 --- a/erpnext/projects/doctype/timesheet/test_timesheet.py +++ b/erpnext/projects/doctype/timesheet/test_timesheet.py @@ -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", {}) diff --git a/erpnext/tests/utils.py b/erpnext/tests/utils.py index b0fb36fb757..ae61bc6c522 100644 --- a/erpnext/tests/utils.py +++ b/erpnext/tests/utils.py @@ -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: