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.pyin my custom appfrom __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.pyfile, 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 .