How to add a field to "item" DocType without changing ERPNext source code?

I need to add a new field into “item” DocType. I managed to do it by modifying source code (frappe-bench/apps/erpnext/erpnext/stock/doctype/item) and it works fine.

But I’m afraid it might break during the update. I know that in Odoo for this purpose inheritance is used, so there you can create a custom module (let’s call it my_stock) and there inherit the original module, add what you need, and be sure that when you move to a new version nothing will break. Is there any way to do the same in ERPNext? (add a new field to a DocType without changing source code)?

Yes, you can add as many as custom fields to Standard Doctype without breaking during upgrade.

For this purpose use the Customize Form option.

If you edit directly source code, your upgrade will be definitely failed.

1 Like

https://docs.erpnext.com/docs/v13/user/manual/en/customize-erpnext/customize-form

1 Like

Thank you! It works.
A Newly added custom field appeared where it should.
But I’m a little disappointed, I noticed that it is stored in the “tubCustom Field” table in the database.
I can’t commit this change through git. Is there any way to track such changes?

In order to achieve this, you have to add the custom field using hooks.

1 Like

This seems to be what I need!

So, I have to create a separate application, and add to hooks.py something like this:

override_doctype_class = {

"ToDo": "custom_app.overrides.CustomToDo"

}

And override “item” doctype.

Is this the right way?

Is there any documentation on hooks?

Refer to this document:

https://frappeframework.com/docs/v13/user/en/python-api/hooks

1 Like