Why on_submit called twice?

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

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"

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