Hi folks,
I am starting to code on ERPNext platform. My question might be again very basic. Please bear me.
But, what do we mean when we actually pass (doc,method=None) to a function in python?
many times, I came across python functions such as:
def update_completed_and_requested_qty(stock_entry, method=None):
def stock_entry(doc,method=None)
Thanks in advance.
Okay, you are talking about doc_event functions,
Now suppose you submitted a document of type Stock Entry
,
We have a hook that gets executed which is called on_submit
In hooks.py
file you will find something like this:
doc_events = {
"Stock Entry": {
"on_submit": "erpnext.stock.doctype.material_request.material_request.update_completed_and_requested_qty",
"on_cancel": "erpnext.stock.doctype.material_request.material_request.update_completed_and_requested_qty"
},
hence your update_completed_and_requested_qty
,
now the code above means that whenever we submit a Stock Entry
document,
The on_submit
hook will be triggered,
and this line:
"on_submit": "erpnext.stock.doctype.material_request.material_request.update_completed_and_requested_qty",
triggers update_completed_and_requested_qty
whenever on_submit
is triggered
update_completed_and_requested_qty
is called a doc_event
and each doc_event passes two values doc
and method
The doc
variable contains the current document that triggered the on_submit function for example and it contains the whole document as an object,
which means you have access to all its values,
Now method
on the other hand only contains the name of the original hook (trigger)
which is in this case on_submit
.
I hope this is clear enough,
to read more about hooks, follow this link
3 Likes
Thank you for your precious time.
It is very useful information indeed.
Thanks Once again!
1 Like