Revert "fix: Reserve and Unreserve buttons visibility in SO"
This reverts commit cdb31816918c8d07344f9af4b7cdf43d0f2b959e.
diff --git a/erpnext/selling/doctype/sales_order/sales_order.js b/erpnext/selling/doctype/sales_order/sales_order.js
index 417e93b..37c2294 100644
--- a/erpnext/selling/doctype/sales_order/sales_order.js
+++ b/erpnext/selling/doctype/sales_order/sales_order.js
@@ -66,16 +66,18 @@
}
if (frm.is_new()) {
- if (frm.doc.__onload && frm.doc.__onload.enable_stock_reservation) {
- if (frm.doc.__onload.reserve_stock_on_so_submission) {
- // If `Reserve Stock on Sales Order Submission` is enabled in Stock Settings, set Reserve Stock to 1 else 0.
- frm.set_value("reserve_stock", value ? 1 : 0);
+ 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 `Reserve Stock on Sales Order Submission` is enabled in Stock Settings, set Reserve Stock to 1 else 0.
+ frm.set_value("reserve_stock", value ? 1 : 0);
+ })
+ } else {
+ // If `Stock Reservation` is disabled in Stock Settings, set Reserve Stock to 0 and read only.
+ frm.set_value("reserve_stock", 0);
+ frm.set_df_property("reserve_stock", "read_only", 1);
}
- } else {
- // If `Stock Reservation` is disabled in Stock Settings, set Reserve Stock to 0 and read only.
- frm.set_value("reserve_stock", 0);
- frm.set_df_property("reserve_stock", "read_only", 1);
- }
+ })
}
}
},
@@ -287,7 +289,7 @@
}
// Stock Reservation > Reserve button will be only visible if the SO has unreserved stock.
- if (this.frm.doc.__onload && this.frm.doc.__onload.enable_stock_reservation && this.frm.doc.__onload.has_unreserved_stock) {
+ if (this.frm.doc.__onload && this.frm.doc.__onload.has_unreserved_stock) {
this.frm.add_custom_button(__('Reserve'), () => this.create_stock_reservation_entries(), __('Stock Reservation'));
}
diff --git a/erpnext/selling/doctype/sales_order/sales_order.py b/erpnext/selling/doctype/sales_order/sales_order.py
index 6abb8ed..e9b5c0f 100755
--- a/erpnext/selling/doctype/sales_order/sales_order.py
+++ b/erpnext/selling/doctype/sales_order/sales_order.py
@@ -50,13 +50,12 @@
super(SalesOrder, self).__init__(*args, **kwargs)
def onload(self) -> None:
- stock_settings = frappe.get_doc("Stock Settings")
- self.set_onload("enable_stock_reservation", stock_settings.enable_stock_reservation)
- self.set_onload(
- "reserve_stock_on_so_submission", stock_settings.reserve_stock_on_sales_order_submission
- )
- self.set_onload("has_reserved_stock", has_reserved_stock(self.doctype, self.name))
- self.set_onload("has_unreserved_stock", self.has_unreserved_stock())
+ if frappe.get_cached_value("Stock Settings", None, "enable_stock_reservation"):
+ if self.has_unreserved_stock():
+ self.set_onload("has_unreserved_stock", True)
+
+ if has_reserved_stock(self.doctype, self.name):
+ self.set_onload("has_reserved_stock", True)
def validate(self):
super(SalesOrder, self).validate()