What do you expect to customize?

Hello,

We have seen “how to customize X” post many many times on forums… We are trying to form guidelines and a curated list of approaches to typical customizations.

Why?

Frappe is super customizable and often a bit too much because custom apps allows you to shoot yourself on the foot very easily if you’re not careful. Primarily I believe two things are important when doing customizations:

  1. Customizations need to be sustainable i.e. shouldn’t break in minor version upgrades and minimal breakages in major upgrades.
  2. Customizations need to be “correct”, i.e. they shouldn’t cause issues with core behavior.

Sustainable customizations in order of increasing “power”:

  1. “Customize form”
  2. Client script for list/form view
  3. Server scripts - hooks, scheduler, API
  4. Apps using hooks to override behavior expected to be overridden.

Unsustainable customizations:

  1. Going against core business logic. (like rolling your own GL entry functions)
  2. Fiddling with database transactions without knowing how they work (like db.commit and db.rollbackread more here) You can avoid these in most cases.
  3. Monkey patches. VERY dangerous and unmaintainable.

We are in process of collecting list of common use cases that users want to customize and approaches to them in form of docs + a webinar. Feel free to share your suggestions here.

ref:

7 Likes

This is what I follow.

  • Custom fields:
    • Add a prefix to custom fields. e.g. If there is a field needed for “installation” call it “cepl_installation”, Instead of “cepl” it can be any logical prefix.
    • Add custom fields on Standard DocTypes only. For custom doctypes edit doctype itself.
  • Property Setter:
    • Add property setter for Standard DocTypes only. For custom doctypes edit doctype itself.
    • filter property setters in hooks.py -> fixtures of the app.
  • Prefix always makes sure our fields and doctypes remain separate from official or community apps.
  • Custom DocType: Add Prefix e.g. CEPL Installation instead of just Installation
  • Custom Script: Use hooks.py if possible to add {doctype}_js scripts instead of adding them from ui.
  • Fixtures: Use fine grained filters in hooks.py to export fixtures. That way each app can export or import filtered fixtures instead of all apps exporting and importing all fixtures.
  • Use list of existing whitelisted functions and ReST API. It can achieve a lot without customization.
9 Likes

Also while adding a new custom field, if you want the fieldname to be something like my_custom_field and the label to be Enter data here, simple save the field with the label my_custom_field first. Then you will have the desired fieldname and you can change the label later.

It’s only fieldnames that are static, not labels!

Also, while overriding document classes, make sure to extend it from the original one, be it client or server side. While shipping your apps, make sure you have all the required custom fields as fixtures within it.

And while deleting custom apps, have a script run after the uninstall to remove any Link fields pointing to the DocTypes of that app.

5 Likes

This might help on the naming guidelines - Naming Guidelines · frappe/erpnext Wiki · GitHub

2 Likes