Override standard controller methods in erpnext with custom app

Override standard controller methods in erpnext with custom app like (calculate_contribution method in selling controller)

1 Like

Check the docs here Hooks

In your custom app custom_app/custom_app/__int__.py file

For Example

from erpnext.controllers.taxes_and_totals import calculate_taxes_and_totals
from custom_app...<path_to_file> import calculate_item_values
calculate_taxes_and_totals.calculate_item_values = calculate_item_values

4 Likes

@jamsheer Hello brother, I’ve tried to add the first line(from erpnext.controllers…) that you’ve mentioned. But I don’t know how to set path for the custom path? What is that custom path means(from custom_app…<path_to_file> import )? Could you please elaborate this?

Thanks in advance!!!

Custom app means the frappe app that you created

That worked, thanks

This article helped me

1 Like

@jamsheer hello brother, if that is overriding the py file, do i need to also override the js/controllers/taxes_and_totals.js?

did you able to override controller methods of erpnext, if yes then please help?

I want to override erpnext.PointOfSale.Controller = class {
check_stock_availability() {}
}

I don’t know why have you mentioned it as closed but here it is:

  1. Create the overrides folder in your project and your ide will include (or it is already included) init.py
  2. start by importing the class of the method (or the Doctype) you are overriding and define your class as mySubClass(FrappeErpnextBuiltInClass)
  3. once you define the overriden method in your custom overriding class, the FrappeErpnextBuiltInClass method will be overridden by the method you define in mySubClass method.
  4. go find hooks.py in your custom app root folder, there you will need to define overriding classes such as below:
override_doctype_class = {
    "Frappe Erpnext Built In Class  ": "customersproject.overrides.mySubClass.mySubClass"
}

Notice the doctype notation. Hope this sheds some light on what you are doing.