Skip to content

Instantly share code, notes, and snippets.

@agritheory
Created November 27, 2019 13:08
Show Gist options
  • Save agritheory/2070d04fd899e2fff2cb9c135bdacd8c to your computer and use it in GitHub Desktop.
Save agritheory/2070d04fd899e2fff2cb9c135bdacd8c to your computer and use it in GitHub Desktop.
Basic document hook (snippets)
doc_events = {
"Sales Order": {
"on_submit": "my_custom_app.workflows.make_stock_entry_on_so_submit"
},
"on_cancel": "my_custom_app.workflows.cancel_stock_entry_on_so_cancel"
}
}
# located in the same directory of my_custom_app as hooks.py
@frappe.whitelist()
def make_stock_entry_on_so_submit(so, method): # required arguments
doc = frappe.new_doc("Stock Entry")
# move data to your stock entry record from sales order
doc.save()
doc.submit()
so.stock_entry = doc.name # so.stock_entry is a custom field
return so
@frappe.whitelist()
def cancel_stock_entry_on_so_cancel(so, method): # required arguments
doc = frappe.get_doc("Stock Entry", so.stock_entry) # decide how you want to store a related stock entry, probably a custom field
doc.cancel()
so.stock_entry = ""
return so
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment