Task-types required for Custom App - Github install

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

  1. Define the after_migrate Hook:
    In your app’s hooks.py file, include the after_migrate hook and point it to a custom method.

    after_migrate = "your_app.utils.create_task_types"
    
  2. Write the create_task_types Function:
    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

1 Like