Override whitelisted method using custom app is not working

I tried to ovrride whitelisted using custom app hooks

but for this function,it ios not working

Hi,
Any updates . I am facing the same issue.

from erpnext/frappe which method you try to override ?

I am trying to override a method from erpnext healthcare utils.py, get_healthcare_services_to_invoice to be specific.
My hooks.py

override_whitelisted_methods = {
    "erpnext.healthcare.get_healthcare_services_to_invoice": "custom_cmh.custom_cmh.utils.get_healthcare_services_to_invoice"
}

I could execute the override method from command line, so the path is absolutely fine.

$bench --site xxxx execute custom_cmh.custom_cmh.utils.get_healthcare_services_to_invoice

@nabinhait need to investigate the issue why hook override does not work with all whitelisted method.

Hi

I use the method to override whitelist method:

  • In my custom app, I make python file with the same name of doctype, for example, I needed to add some functionality to Staffin Plan so I make file staffing_plan.py in my custom app

      from __future__ import unicode_literals
      import frappe
      from frappe.model.document import Document
      from frappe import _
      from frappe.utils import getdate, nowdate, cint, flt
      from erpnext.hr.doctype.staffing_plan import staffing_plan
      
      def get_company_set(company):
      	return frappe.db.sql_list("""
      		SELECT
      			name
      		FROM `tabCompany`
      		WHERE
      			parent_company=%(company)s
      			OR name=%(company)s
      	""", (dict(company=company)))
          
      def override_get_designation_counts(doc, method):
          @frappe.whitelist()
          def get_designation_counts_overrided(designation, company, branch=None):
              if not designation:
                  return False
      
              employee_counts = {}
              company_set = get_company_set(company)
              if not branch:
                  employee_counts["employee_count"] = frappe.db.get_value("Employee",
                      filters={
                          'designation': designation,
                          'status': 'Active',
                          'company': ('in', company_set),
                      }, fieldname=['count(name)'])
              else:
                  employee_counts["employee_count"] = frappe.db.get_value("Employee",
                      filters={
                          'designation': designation,
                          'status': 'Active',
                          'company': ('in', company_set),
                          'branch' : branch,
                      }, fieldname=['count(name)'])
      
              employee_counts['job_openings'] = frappe.db.get_value("Job Opening",
                  filters={
                      'designation': designation,
                      'status': 'Open',
                      'company': ('in', company_set)
                  }, fieldname=['count(name)'])
      
              return employee_counts
          staffing_plan.get_designation_counts = get_designation_counts_overrided
    
  • Then in hooks.py file, I use this:

      doc_events = {
           "Staffing Plan": {
      		         "onload":[
                              "custom1.custom_hokks.staffing_plan.override_get_designation_counts",
                      ],
                      "refresh":[
                              "custom1.custom_hokks.staffing_plan.override_get_designation_counts",
                      ],
                      "reload":[
                              "custom1.custom_hokks.staffing_plan.override_get_designation_counts",
                      ],
                      "before_insert":[
                              "custom1.custom_hokks.staffing_plan.override_get_designation_counts",
                      ],
           },
      }
    

And it works like charm.

I hope this helps .

3 Likes