Override whitelisted method

Hello all,
I am trying to override the below whitelisted function.

I have added it in hooks in override_whitelisted_methods also. But it still seems to run the core function still instead of the custom one. I have overriden others which are working fine, only having problem with this one. Checked the path of both the functions and it is also correct.

Any pointers what might be the issue?

I’m having the same problem. I’m trying to override the following whitelisted function:

I’ve added the following to my custom app’s hooks.py:

override_whitelisted_methods = {
    "erpnext.setup.doctype.party_type.party_type.get_party_type": "my_app.my_module.utils.get_party_type"

The path to the method has already been tested to be correct. So it cannot just be a wrong path.

Not sure if same thing happens to all other whitelisted methods elsewhere in the ERPNext or Frappe apps. Hopefully someone has an idea what’s going on. Or at least an idea where to check for the problem.

Other whitelisted methods are working as mentioned in the screenshot above.
Regarding your issue, I believe this function is being called by a link field.
If so you can write a function in your custom app and set use set_query for that link field.

Yes, that’s right - the method is called by a link field really. I’ll try your suggestion. Thanks.

Did the first override get_product_info_for_website work for you when loading product in website? Checking frappe/frappe/handler.py seems like the hooks are never called for website methods as there is no “cmd” in the request

@kartik, does override works for you in v12?

Sorry. No idea. I faced this issue on v11.

Is this work on versio12?

If I’m not mistaken.

This will work on version 12 but it will work only if method get call directly with url such as



	'method': 'erpnext.buying.doctype.purchase_order.purchase_order.make_purchase_receipt'

But it won’t work with method that got call indirectly such as.

make_purchase_receipt: function() {
		method: "erpnext.buying.doctype.purchase_order.purchase_order.make_purchase_receipt",
		frm: cur_frm

Which got call through frappe.model.open_mapped_doc method.

Overriding happen in execute_cmd function which you can find it here.

@pipech Thank you so much
here is my used case . can you help me to solve ?

create_opportunity: function () {
		method: "erpnext.crm.doctype.lead.lead.make_opportunity",
		frm: cur_frm

whitelisted function is
def make_opportunity(source_name, target_doc=None):
def set_missing_values(source, target):
_set_missing_values(source, target)

target_doc = get_mapped_doc("Lead", source_name,
	{"Lead": {
		"doctype": "Opportunity",
		"field_map": {
			"campaign_name": "campaign",
			"doctype": "opportunity_from",
			"name": "party_name",
			"lead_name": "contact_display",
			"company_name": "customer_name",
			"email_id": "contact_email",
			"mobile_no": "contact_mobile"
//i want to add one line here "customer":"customer"
	}}, target_doc, set_missing_values)

return target_doc

I think you need to override JS method then redirect it to your custom python method.

1 Like

In order to override server side whitelisted method, i did the following.
This works for v11.

  1. In hooks.py add this
override_whitelisted_methods = {
	"frappe.abc.xyz.main_method": "custom_app.xyz.custom_method_name"
  1. In you custom_app/xyz file, add this method as whitelisted method
def custom_method_name():

May I know how to add in hooks.py whether to override new frappe.whitelist function in sales invoice item.

Hi all,

What if the frappe whitelist method in class.

how to override that?
For example:


you can override the doctype class itself

1 Like

Thank you for your response.

I tried override from doctype_js = {
in hooks.

But is not reflected, What I am trying is child table, name crm_note.

CRMNote is a class that is inherited by other doctypes. Eg: https://github.com/frappe/erpnext/blob/f09e2130a1a3ca999247f89f76c20efcc003b450/erpnext/crm/doctype/prospect/prospect.py#L14

Lets say you want to override the add_note function for prospect.
You can override the doctype class of Prospect and add a function with the same name and your desired function and whitelist it.

1 Like