diff --git a/erpnext/selling/doctype/sales_order/sales_order.js b/erpnext/selling/doctype/sales_order/sales_order.js index 0a385c590c..6b3826b33e 100644 --- a/erpnext/selling/doctype/sales_order/sales_order.js +++ b/erpnext/selling/doctype/sales_order/sales_order.js @@ -47,17 +47,7 @@ frappe.ui.form.on("Sales Order", { frm.set_df_property('packed_items', 'cannot_add_rows', true); frm.set_df_property('packed_items', 'cannot_delete_rows', true); - frappe.db.get_single_value("Stock Settings", "enable_stock_reservation").then((value) => { - if (value) { - frappe.db.get_single_value("Stock Settings", "reserve_stock_on_sales_order_submission").then((value) => { - if (value) { - frm.set_value("reserve_stock", 1); - } - }) - } else { - frm.set_df_property("reserve_stock", "read_only", 1); - } - }) + }, refresh: function(frm) { if(frm.doc.docstatus === 1 && frm.doc.status !== 'Closed' @@ -72,8 +62,25 @@ frappe.ui.form.on("Sales Order", { }); } - if (frm.doc.docstatus === 0 && frm.doc.is_internal_customer) { - frm.events.get_items_from_internal_purchase_order(frm); + if (frm.doc.docstatus === 0) { + if (frm.doc.is_internal_customer) { + frm.events.get_items_from_internal_purchase_order(frm); + } + + frappe.db.get_single_value("Stock Settings", "enable_stock_reservation").then((value) => { + if (value) { + frappe.db.get_single_value("Stock Settings", "reserve_stock_on_sales_order_submission").then((value) => { + if (value) { + frm.set_value("reserve_stock", 1); + } else { + frm.set_value("reserve_stock", 0); + } + }) + } else { + frm.set_value("reserve_stock", 0); + frm.set_df_property("reserve_stock", "read_only", 1); + } + }) } },