Try ERPNext Buy Support Partners Foundation

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

http://site1.local:8000/api/method/erpnext.buying.doctype.purchase_order.purchase_order.make_purchase_receiptttp://site1.local:8000/api/method

or

frappe.call({
	'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() {
	frappe.model.open_mapped_doc({
		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 () {
	frappe.model.open_mapped_doc({
		method: "erpnext.crm.doctype.lead.lead.make_opportunity",
		frm: cur_frm
	})
},

whitelisted function is
@frappe.whitelist()
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