I have some Validationes that I want to perform in the leave application, these checks need to be performed before canceling but what happened is that the system canceled the associated document (attendance) and then executed the code
import frappe
from frappe.desk.form.linked_with import get_submitted_linked_docs
original_get_submitted_linked_docs = get_submitted_linked_docs
@frappe.whitelist()
def get_submitted_linked_docs(doctype: str, name: str) -> list[tuple]:
res = frappe.get_doc(doctype, name).run_method('before_cancel')
# if return value of 'before_cancel' equal true will skip the linked documents validations
# and show the delete confirmation massage direct and you can handel the remain code
# after delete confiramtion by stander event on_cancel
if res == True:
return {'docs': [], 'count': 0}
return original_get_submitted_linked_docs (doctype ,name)
frappe.desk.form.linked_with.get_submitted_linked_docs = get_submitted_linked_docs