This document explains how ERPNext wires demo data into the install/setup experience, how the data is produced, and how you can replicate the pattern in another Frappe app.
ERPNext adds a “Generate Demo Data for Exploration” checkbox to the setup wizard. This is defined in the setup wizard front-end slide configuration (setup_wizard.js) under the organization slide as the setup_demo field. When checked, its value is included in the setup wizard payload. 【F:erpnext/public/js/setup_wizard.js†L30-L74】
ERPNext’s hooks.py connects the setup wizard’s completion hook to erpnext.setup.setup_wizard.setup_wizard.setup_demo. This is the hook the Frappe setup flow calls when the wizard finishes. 【F:erpnext/hooks.py†L65-L70】
Inside setup_wizard.py, the setup_demo function checks the incoming args for setup_demo and, if present, enqueues demo data creation after the setup transaction commits. This keeps demo creation asynchronous and ensures it only runs after the base setup is persisted. 【F:erpnext/setup/setup_wizard/setup_wizard.py†L67-L70】
ERPNext’s demo pipeline is in erpnext/setup/demo.py:
setup_demo_data()is the entry point. It creates a demo company, loads demo master data, and then creates demo transactions. It also clears cache keys and publishes a realtime event on success. 【F:erpnext/setup/demo.py†L18-L36】- Company cloning:
create_demo_company()takes the first existing Company, creates a “(Demo)” company, sets it as default, and adds a demo bank account. It also records the demo company in Global Defaults for later cleanup. 【F:erpnext/setup/demo.py†L59-L83】 - Master data:
process_masters()iteratesdemo_master_doctypesfrom hooks and loads JSON fixtures fromerpnext/setup/demo_data/*.json(viaread_data_file_using_hooks) before inserting them. 【F:erpnext/setup/demo.py†L85-L101】【F:erpnext/setup/demo.py†L225-L231】 - Transactions:
make_transactions()iteratesdemo_transaction_doctypesfrom hooks, loads JSON fixtures, and creates transactions with dates/warehouses adjusted for the demo company. It then converts some orders into invoices and payments. 【F:erpnext/setup/demo.py†L104-L175】 - Data source:
read_data_file_using_hooks()reads the JSON fixtures fromerpnext/setup/demo_databased on the doctype key. 【F:erpnext/setup/demo.py†L225-L231】
The doctype lists that drive which JSON files are loaded are defined in hooks.py as demo_master_doctypes and demo_transaction_doctypes. 【F:erpnext/hooks.py†L95-L106】
ERPNext exposes clear_demo_data() as a whitelisted method. It uses the demo company recorded in Global Defaults to delete demo transactions and masters, then deletes the demo company itself. This is the counterpart to demo setup and is essential for reversible demo installs. 【F:erpnext/setup/demo.py†L37-L83】【F:erpnext/setup/demo.py†L194-L223】
Use the ERPNext wiring as a blueprint:
-
Expose a setup option in the wizard UI
- Add a checkbox (e.g.,
setup_demo) to your setup wizard UI so the user can opt in. ERPNext does this inerpnext/public/js/setup_wizard.js. 【F:erpnext/public/js/setup_wizard.js†L30-L74】
- Add a checkbox (e.g.,
-
Wire a completion hook in
hooks.py- Set
setup_wizard_completeto your app’s handler (e.g.,my_app.setup.setup_wizard.setup_demo). ERPNext wires this toerpnext.setup.setup_wizard.setup_wizard.setup_demo. 【F:erpnext/hooks.py†L65-L70】
- Set
-
Enqueue demo creation after commit
- In your setup handler, check the incoming args and enqueue your demo job with
enqueue_after_commit=Trueso base setup is committed before demo data is inserted. This pattern is shown in ERPNext’ssetup_demo()implementation. 【F:erpnext/setup/setup_wizard/setup_wizard.py†L67-L70】
- In your setup handler, check the incoming args and enqueue your demo job with
-
Define demo doctypes in hooks
- Add
demo_master_doctypesanddemo_transaction_doctypesin your app’shooks.py. ERPNext uses these lists to decide which JSON fixtures to load. 【F:erpnext/hooks.py†L95-L106】
- Add
-
Store demo fixtures in your app
- Place JSON fixtures under a predictable location (ERPNext uses
erpnext/setup/demo_data) and load them dynamically so you can use hooks to decide which files are used. 【F:erpnext/setup/demo.py†L85-L101】【F:erpnext/setup/demo.py†L225-L231】
- Place JSON fixtures under a predictable location (ERPNext uses
-
Provide cleanup/reset
- Implement a
clear_demo_data()or equivalent to delete the demo company and any demo data. ERPNext uses Global Defaults (demo_company) to keep a stable reference for cleanup. 【F:erpnext/setup/demo.py†L37-L83】【F:erpnext/setup/demo.py†L194-L223】
- Implement a
- User checks Generate Demo Data during setup. 【F:erpnext/public/js/setup_wizard.js†L30-L74】
- Setup wizard completes and
setup_wizard_completecalls ERPNext’ssetup_demohook. 【F:erpnext/hooks.py†L65-L70】 setup_demoenqueuessetup_demo_dataafter commit. 【F:erpnext/setup/setup_wizard/setup_wizard.py†L67-L70】setup_demo_datacreates the demo company, loads masters, and inserts demo transactions from JSON fixtures. 【F:erpnext/setup/demo.py†L18-L175】- Demo data can be cleared later via
clear_demo_data(). 【F:erpnext/setup/demo.py†L37-L83】【F:erpnext/setup/demo.py†L194-L223】