Web hook when Purchase order is Closed is not triggering

When i try to create a new Webhook on purchase Order status changing to Close is not triggering.
Could you please help me with this, Where i exactly i kept wrong.

you made no mistake, because Close purchase order is technically by doc.db_set which does not trigger doc events.

Thank you Szufisher for quick reply. Is there any work around to trigger webhook and make an Api call in this scenario.
Any suggestion would be appreciated.

override this whitelist method in purchase_order.py, manually trigger the on_update in your custom code.
def close_or_unclose_purchase_orders

Could you please provide any sample code link for reference

Hi @szufisher ,

Can you please help me to override the above method. Where do i need to make change and procedure for this.


  1. create a new custom app, below sample code used fisher_test
  2. in the hooks.py add following code to override the standard whitelist method
# Overriding Methods

# ------------------------------


override_whitelisted_methods = {

"erpnext.buying.doctype.purchase_order.purchase_order.close_or_unclose_purchase_orders": "fisher_test.override.my_close_or_unclose_purchase_orders",

"erpnext.buying.doctype.purchase_order.purchase_order.update_status": "fisher_test.override.my_update_status"

  1. create a new py file with code referenced by the hooks, in the code, call the original method and manually trigger the web hook
import frappe
import json
from erpnext.buying.doctype.purchase_order.purchase_order import (
from frappe.integrations.doctype.webhook import run_webhooks

def my_update_status(status, name):
    update_status(status, name)
    if status == 'Closed':
        po = frappe.get_doc('Purchase Order', name)
        run_webhooks(po, 'on_update')       

def my_close_or_unclose_purchase_orders(names, status):
    close_or_unclose_purchase_orders(names, status)
    if status == 'Closed':
        if isinstance(names, str):
            names = json.loads(names)
        for name in names:
            po = frappe.get_doc('Purchase Order', name)
            run_webhooks(po, 'on_update')