Task-types required for Custom App - Github install

Hi
I have created my own App with all its custom doctypes. Busy with final testing and
then I want to push that to Github.

My App makes use of the Standard Project Management of ERPNext but it requires
some Task_types to be defined. Clearly I can define those Task Types on my own
system, but if someone else wants to use my App , how do I ensure that
these Task Types will be created when my App is installed from Github ?

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

Thank you @NCP for the advice !
Much appreciated !
Although my other Apps integrated with many standard doctypes, this is the first one that requires me to define a particular Task Types. I am setting up filters on
certain doc-fields and if the correct task-type has not been defined, its not going
to work.

Again, Thanks