Custom App: Understanding Fixtures?

The documentation isn’t super clear on exactly what fixtures are for… I’ve watched a few videos on the subject, but I’m still not really clear…

Are fixtures only for migrating data (as in data in the database) from one instance/site to another?

What would developers typically use fixtures for?

For me, one of the main goal of fixtures in app is for : “take a vanilla ERPNext/Frappe, install it and there is no need to make other customization/settings in UI”

All changes that have to be applied when install a custom app :

  • Custom Fields on core DocType
    • for this one you can also export the customize DocType in you app in global, but when bench migrate/update, if the core DocType “update date” is more recent that your “update date” for you customized DocType, your change will be removed, that why use fixture for custom field is nice, it will always be apply on migrate/apply with core changes
  • property of core fields changes (label, display, read only, default print format for a doctype, etc…)
    • but take care, the property setters as fixtures of your app are inserted in DB when install app, remove them from the fixture of your app, on migrate/update this do not remove them from your the table Property setters, you have to remove them manually if you don’t want them anymore (or use migration process in your app to remove them).
  • customization made during “live” design on UI and store in DB, that need to be deployed when custom app is install on a site :
    • SQL query Report
    • Print format
    • Dashboard / Dashboard Card
    • Workspace/Menu
    • Add Role for Doctype
    • New Roles and their linked permissions with Core DocType (for custom DocType that in the custom DocType itself)

I’m sure I forget other use case, but that it, just install the app and it will apply point by point your custom app feature and been keept along with core update

1 Like

Is it possible to use Fixtures to install custom Views for existing DocTypes?

For instance, if I want to make a “Google Map View” for ERPNext Lead DocType?

Note: I’m not talking about Workspaces.

you can create a custom field (type Geolocation) in Lead Doctype and export it in your APP through Hooks.py then use this command for exporting

(bench --site [your-site] export-fixtures )
Note:

  • the location working with the site has SSL

But can I use Fixtures to create a custom View for Leads (not just a new field)?

Thank you for the detailed examples.

Could you elaborate more on this? What is your way of exporting custom permission for core doctypes?

I export Role and Custom DocPerm but they seem very inconsistent, sometimes with migrates, they get duplicated, or wiped out