Why on_submit called twice?

Hi,
I have called on function on_submit from hooks.py.
I don’t know, why its calling twice.

hooks.py code

doc_events = {
    "Job Card": {
        "validate": "sample_register.sample_register.doctype.sample_entry_register.sample_entry_register.status_updator",
        "on_submit": "sample_register.sample_register.doctype.sample_entry_register.sample_entry_register.status_updator"
    }
}

python function

@frappe.whitelist(allow_guest=True)
def status_updator(self, method):
    if self.sample_id and (self.docstatus==1):
        frappe.msgprint("in submit"+self.sample_id)
        sample_entry_doc=frappe.get_doc("Sample Entry Register",self.sample_id)
        sample_entry_doc.job_card_status = "Submitted"
        sample_entry_doc.save()

Submit called twice:

@kolate_sambhaji On submission of a document, validate and on_submit both functions are executed. Thats why you are getting the message twice.

1 Like

@nabinhait thanks for Quick reply!

@nabinhait One more thing
When I am creating new Job Card, I am getting another error Job Card JB0045 not found. because validate called before save

I have solved this using ‘after_save’ doc event and updated frappe documentation
https://github.com/frappe/frappe/pull/1447/files