Skip to content

Instantly share code, notes, and snippets.

@agritheory
Last active January 16, 2021 11:51
Show Gist options
  • Save agritheory/68120813d532fefe88aafbbcc982777d to your computer and use it in GitHub Desktop.
Save agritheory/68120813d532fefe88aafbbcc982777d to your computer and use it in GitHub Desktop.
Hook onto the workflow action API
# Overriding Whitelisted Methods (in my_app/hooks.py)
# ------------------------------
override_whitelisted_methods = {
"frappe.model.workflow.apply_workflow": "my_app.workflows.apply_workflow"
}
# in my_app/workflows.py
import frappe
from frappe.model.workflow import apply_workflow as model_apply_workflow
from six import string_types
import json
@frappe.whitelist(allow_guest=True)
def apply_workflow(doc, action):
if isinstance(doc, string_types):
doc = frappe._dict(json.loads(doc))
print(doc.name, action) # you can perform other logic here
return model_apply_workflow(doc, action)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment