Manage Hooks.py for single customization

Dear All,

We want to add some features on top to Erpnext.
What we like to do is to create a SUB SET of methods in a custom .py class that will be called when events raise (for specific docType); so:

  1. Is possible to create many different hooks.py (one for each doctype), to not change the original one in the application root?

  2. Is possible to call any class method, or it must be a CONTROLLER?
    2.1 In case it must be a controller is possible to inherit the original controller just adding needed methods?

  3. Can i save my classes in .py file in a completely different folder than “frappe” or “erpnext” under “apps” folder? Because we’d like to stay clean and to not change nothing from the original installation, so we are also sure that our changes will not be “removed” after a “bench update”

Eg.: As an example image that on event “before_save” for DocType “sales_order” we want to call our custom function (completely external to ERPNEXT to not change or fork original source code), so this new custom method will create a new, NOT CUSTOM, doctype (like a new sales_order with a specific sales_order_item); and also we want to keep ERPNEXT and FRAPPE installation up-to-date.

How do you think it?

The short Answer is Custom App

Dear Mohammed,

We are looking for long answer :slight_smile:

We like to use FRAPPE FRAMEWORK as well ERPNEXT API, but without changing theirs source code. Like if it is an “add-on”.

One custom app one hook. You can call any class, methods etc. It will not break core codes as far as you maintain it in separate app. Custom app will have its own folder under apps directory

2 Likes