I wrote a custom script for on load for employee doctype lets say:
employee.py:
def onload(self):
frappe.msgprint(“onload called”)
hooks.py:
doc_events = {
“Employee”:{
“onload”:“erpnext.setup.doctype.employee.employee.Employee.onload”
},
getting an error:
ModuleNotFoundError: No module named ‘erpnext.setup.doctype.employee.employee.Employee’; ‘erpnext.setup.doctype.employee.employee’ is not a package
How to resolve this?
Peer
January 14, 2025, 10:33am
2
The DT Employee seems to be in another module.
You can open the doctype list, locate Employee, and see the module it is part of.
Then adapt your “onload” triggered path accordingly.
Peer
January 14, 2025, 10:48am
3
The Employee DT controller lives in:
/apps/frappe/erpnext/setup/doctype/employee/employee.py
See its code here:
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
import frappe
from frappe import _, scrub, throw
from frappe.model.naming import set_name_by_naming_series
from frappe.permissions import (
add_user_permission,
get_doc_permissions,
has_permission,
remove_user_permission,
)
from frappe.utils import cstr, getdate, today, validate_email_address
from frappe.utils.nestedset import NestedSet
from erpnext.utilities.transaction_base import delete_events
class EmployeeUserDisabledError(frappe.ValidationError):
pass
This file has been truncated. show original
Peer
January 14, 2025, 11:05am
4
Here are examples of how the path is built (click to see more of them than shown here):
"Asset",
"Asset Capitalization",
"Asset Repair",
"Delivery Note",
"Landed Cost Voucher",
"Purchase Receipt",
"Stock Reconciliation",
"Subcontracting Receipt",
]
doc_events = {
"*": {
"validate": [
"erpnext.support.doctype.service_level_agreement.service_level_agreement.apply",
"erpnext.setup.doctype.transaction_deletion_record.transaction_deletion_record.check_for_running_deletion_job",
],
},
tuple(period_closing_doctypes): {
"validate": "erpnext.accounts.doctype.accounting_period.accounting_period.validate_accounting_period_on_doc_save",
},
"Stock Entry": {
the path was correct, actually I did not need to specify the onload in hooks.py, it worked fine without it. the problem is when i send data to frontend I wana remove certain fields being sent and displayed on form. but its not wokring, any suggestion it?
doc_dict= self.as_dict()
for field in sensitive_fields:
if field in doc_dict:
// dont send this field to frontend