What is best practice to create custom fields? fixtures or coding?

What is the good practice to create custom fileds?

  1. Fixtures
  2. Manual coding after_install - create_custom_fields()

From all tutorial, when create new custom fields, it is recommended to use export-fixtures. But when come to all good modules we saw, either from erpnext or else, nobody is using fixtures, i.e., erpnext_germany/erpnext_germany/install.py at version-15 · alyf-de/erpnext_germany · GitHub

After develop with ERPNext for a while, personally I also find fixtures error prone when working in team, and it is also hard to track changes as it always mess up.

The fixtures is it is always run on migration, sometime good sometime not desirable. I am not sure if there is way to prevent it form always updating.

But to create custom fields on after_install by coding, is also not very good as development proceeds IMHO. otherwise, as we have more custom fields, do we need to use patches? For me, not very good DX.

So, in this thread, I would like to find the best practice on how experiended developers is doing.

For me:

  • Modules, i.e., to be in marketplace - avoid using export-fixtures
  • Module for customer project - it is ok to use exort-fixtures

Note: In my first project, I was also using Export Customizations and that is totally horrible when come to team development.

What are your best practices?

2 Likes

For team of developers,

I am learning the hard way that…

  1. Export customizatoin form customize form shouldn’t be used at all (horrifying)
  2. bench export-fixtures also shouldn’t be used. It export too much stuff make fixture fields hard to maintain.
  3. Create the custom field, property setter by yourself (manually) and use function create_custom_fields() is the only way to ensure clean code.

I.e., hrms/hrms/setup.py at develop · frappe/hrms · GitHub

I would suggest you go with the third one if you don’t have many fields; otherwise, go with the first one. I have many custom fields, so I am using the first one because it is better compared to the second option.