On_submit event not working as per expected in frappe cloud

Hello,

I added an on_submit event to the sales invoice to perform an action, and if this action fails, I throw an error to prevent the document from being submitted.

This works perfectly on my local setup, but when I update it in Frappe Cloud, it’s not functioning as expected.

The issue in Frappe Cloud is that when I attempt to submit the document and the action fails, it throws an error as it should. However, when I refresh the document, it is automatically submitted.

Why does this issue occur in Frappe Cloud but not in my local environment?

hooks.py
doc_events = {
“Sales Invoice”: {
“on_submit”: “nextpty_customization.e_invoice.e_invoice_apis.check_for_auto_e_invoice”,
}
}

raise exception and show error message

frappe.msgprint(f"“”Message: {response[‘message’]}
Description: {response[‘description’]}
View E-Invoice Logs“”", “E-Invoice Creation Failed.”, indicator=‘red’, raise_exception=True)

@pithiya_Nilesh are you running a different version on cloud than your local ?

@bahaou yes, i am using different version but both are in version-15
Local Version →

ERPNext: v15.32.1 (version-15)
Frappe Framework: v15.x.x-develop () (develop)

Frappe Cloud Version →

ERPNext: v15.33.0 (HEAD)
Frappe Framework: v15.38.0 (HEAD)

@pithiya_Nilesh try before_submit , and also try the frappe.throw("message") function

thank you @bahaou i use before_submit and now its working as excepted.
i have same issue in on_update so, before_update can solve my this same problem ?

@pithiya_Nilesh any before action will be triggered before the actual action .