Override non doctype and non whitelist method

Hi is there another workarround to override class py for non doctype and non whitelist def method? anyone

thanks

@Johnrech_Cabatana Can you please more specific about non doctype?

Hi @Johnrech_Cabatana:

I think this is unsupported way … but it works

Sample to override boot (non doctype class / whitelisted method)

On hooks.py add:

import frappe.boot
import your_module.utils
frappe.boot.get_user_info = your_module.utils.custom_get_user_info

On your utils.py file

from frappe.boot import add_user_info
import frappe

@frappe.whitelist()
def custom_get_user_info():
    print("----------------------- I am here! Where are you? ----------------------")
    user_info = frappe._dict()
    add_user_info(frappe.session.user, user_info)

    if frappe.session.user == "Administrator" and user_info.Administrator.email:
        user_info[user_info.Administrator.email] = user_info.Administrator

    return user_info

Or even cleaner way :slight_smile: :

from frappe.boot import get_user_info as original_get_user_info
import frappe

@frappe.whitelist()
def custom_get_user_info():
    print("----------------------- I am here! Where are you? ----------------------")
    return original_get_user_info()
    

Hope this helps.

Hello, this is the file i want to be customize

Thanks, will try this

Hey @avc if i use a cleaner way i don’t have to add any thing to the hooks file

Hi @imbra:

Hooks.py entry is needed anyway

Thank you