You can use the after_migrate hook in your app’s hooks.py file. This hook is executed after migrations are applied, making it a suitable place to check for and create the required Task Types.
Here’s how you can implement it:
Steps to Add Task Types Using after_migrate
-
Define the
after_migrateHook:
In your app’shooks.pyfile, include theafter_migratehook and point it to a custom method.after_migrate = "your_app.utils.create_task_types" -
Write the
create_task_typesFunction:
In a Python file (e.g.,your_app/utils.py), write the function that checks if the Task Types exist and creates them if they don’t.import frappe def create_task_types(): required_task_types = ["Design", "Development", "Testing", "Deployment"] for task_type in required_task_types: if not frappe.db.exists("Task Type", task_type): # Create the Task Type doc = frappe.get_doc({ "doctype": "Task Type", "task_type": task_type }) doc.insert(ignore_permissions=True) frappe.db.commit()
Optional Way: Use Fixtures