On Submit : hooks vs doctype code

Hi

When I do customization, I often search the existing ERPNext code. I saw some thing
the other day which I would like to make sure that I understand it …

Clearly you can have your “on_submit” trigger-code on your doctype code. But I can also put that in the “hooks.py” file.

Which is best ?
My thoughts were …
If you want to add additional “on_submit” code to an existing doctype, then use
hooks.py. But it you are writing code for your own custom doctype , then its best to
place that code in the doctype-code ?

For your own custom doctypes: Put it in the own doctype class (on_submit method).

For extending existing doctypes (core or from other apps): Use hooks.py via doc_events.

Aah …thank you for your quick response @Jeel !

Makes sense what you are saying.