Automatically add custom print formats when installing a custom app

Is there a way to automatically add custom print formats when installing a custom app?

I have a custom app that needs 2 print formats. Whenever I reinstall the app, the print formats need to be added again. Is there a way to bundle it together with the rest of the app?

Add as fixtures in your app hooks.py file.

fixtures = [
	{
		"doctype": "Print format",
		"filters" : [
                "name",
                "in",
                [
					'yourprintformat'
                ]
             ]
     }
 ]

After this, run bench export-fixtures

Now you will see a .json file with print format data stored in fixtures folder. Push your app to repository and install it in other site. Print format will be there :slight_smile:

This method is valid for any object stored in database (custom fields, reports, even predefined data in doctypes, etc …)

Hope this helps.

2 Likes