From 3ecc39a51faee0fa460e511ea0a8705a231921bc Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Sun, 4 May 2025 08:43:40 +0530 Subject: [PATCH] refactor(test): make 'Activity Cost' idempotent --- .../activity_cost/test_activity_cost.py | 32 +++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/erpnext/projects/doctype/activity_cost/test_activity_cost.py b/erpnext/projects/doctype/activity_cost/test_activity_cost.py index 03db2fe6d5a..a3eb176693a 100644 --- a/erpnext/projects/doctype/activity_cost/test_activity_cost.py +++ b/erpnext/projects/doctype/activity_cost/test_activity_cost.py @@ -9,13 +9,41 @@ from erpnext.projects.doctype.activity_cost.activity_cost import DuplicationErro class TestActivityCost(IntegrationTestCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.make_employees() + + @classmethod + def make_employees(cls): + records = [ + { + "company": "_Test Company", + "date_of_birth": "1980-01-01", + "date_of_joining": "2010-01-01", + "department": "_Test Department - _TC", + "doctype": "Employee", + "first_name": "_Test Employee", + "gender": "Female", + "naming_series": "_T-Employee-", + "status": "Active", + "user_id": "test@example.com", + }, + ] + cls.employees = [] + for x in records: + if not frappe.db.exists("Employee", {"first_name": x.get("first_name")}): + cls.employees.append(frappe.get_doc(x).insert()) + else: + cls.employees.append(frappe.get_doc("Employee", {"first_name": x.get("first_name")})) + def test_duplication(self): frappe.db.sql("delete from `tabActivity Cost`") activity_cost1 = frappe.new_doc("Activity Cost") activity_cost1.update( { - "employee": "_T-Employee-00001", - "employee_name": "_Test Employee", + "employee": self.employees[0].name, + "employee_name": self.employees[0].first_name, "activity_type": "_Test Activity Type 1", "billing_rate": 100, "costing_rate": 50,