Serer Script "After Save" is executing two time "On Save" and "On Submit" of document

Hello Community,

I am trying to Submit a Stock Entry “Material Transfer” on Saving of Sales Order.

Warehouses : “Parent WH” and “Child WH”
Item : Item001
Actual Qty : 10Nos. in Parent WH
Actual Qty : 0 Nos in Child WH

Now When “Sales Order” is saved for Item001 with Qty. 1,
A Stock Entry Should be Submitted to transfer material from Parent WH to Child WH for Qty 1.

When I am “testing” below Server Script with default data on Doctype Event “After Save”, Its submitting Stock Entry two times first is on After Save and another on Submit.

stock_entry = frappe.get_doc({
    "doctype": "Stock Entry",
    "stock_entry_type": "Material Transfer"
})

stock_entry.append('items', {
    "s_warehouse": "Parent WH - MC",
    "t_warehouse": "Child WH - MC",
    "item_code": "Item001",
    "qty": 1,
    "uom": "Nos"
})

stock_entry.insert().submit()

What I am doing wrong?

Ok.
So I tried above code by applying condition for docstatus and its just working as I wanted.

if doc.docstatus == 0:
    stock_entry = frappe.get_doc({
        "doctype": "Stock Entry",
        "stock_entry_type": "Material Transfer"
    })
    
    stock_entry.append('items', {
        "s_warehouse": "Child WH - MC",
        "t_warehouse": "Parent WH - MC",
        "item_code": "Item001",
        "qty": 1,
        "uom": "Nos"
    })
    
    stock_entry.insert().submit()

I don’t know if it’s correct way or not.
If anyone has a suggestions or hint please reply.
Thanks.