1.hook.py
doc_events = {
“*”: {
“on_change”: “your_app.overrides.on_change_docs”,
}
}
2. overrides.py
import frappe
from frappe.model.workflow import validate_workflow as core_validate_workflow # Import core workflow validation
from frappe.model.workflow import set_workflow_state_on_action
from frappe.model.document import Document as CoreDocument # Import core Document class
###################### It apply all documents #########################
def on_change_docs(self, method):
validate_workflow(self)
def validate_workflow(self):
“”“Validate if the workflow transition is valid”“”
if frappe.flags.in_install == “frappe”:
return
workflow = self.meta.get_workflow()
if workflow:
# Stop validation if doc is “HFL Package” and user is “Guest”
if self.doctype == “HFL Package” and frappe.session.user == “Guest”:
return
core_validate_workflow(self)
print(f’self {type(self)}: {self.doctype}')
if not self._action == “save”:
set_workflow_state_on_action(self, workflow, self._action)
Override the validate_workflow method in the Document class
CoreDocument.validate_workflow = validate_workflow