fix: Server side validation for Warehouses
diff --git a/erpnext/stock/doctype/stock_settings/stock_settings.js b/erpnext/stock/doctype/stock_settings/stock_settings.js
index 755c430..cc0e2cf 100644
--- a/erpnext/stock/doctype/stock_settings/stock_settings.js
+++ b/erpnext/stock/doctype/stock_settings/stock_settings.js
@@ -5,11 +5,11 @@
refresh: function(frm) {
let filters = function() {
return {
- filters : {
+ filters : {
is_group : 0
- }
+ }
};
- }
+ };
frm.set_query("default_warehouse", filters);
frm.set_query("sample_retention_warehouse", filters);
diff --git a/erpnext/stock/doctype/stock_settings/stock_settings.py b/erpnext/stock/doctype/stock_settings/stock_settings.py
index 65de2e5..93b5eee 100644
--- a/erpnext/stock/doctype/stock_settings/stock_settings.py
+++ b/erpnext/stock/doctype/stock_settings/stock_settings.py
@@ -30,9 +30,17 @@
frappe.make_property_setter({'fieldname': name, 'property': 'hidden',
'value': 0 if self.show_barcode_field else 1})
+ self.validate_warehouses()
self.cant_change_valuation_method()
self.validate_clean_description_html()
+ def validate_warehouses(self):
+ warehouse_fields = ["default_warehouse", "sample_retention_warehouse"]
+ for field in warehouse_fields:
+ if frappe.db.get_value("Warehouse", self.get(field), "is_group"):
+ frappe.throw(_("Group Warehouses cannot be used in transactions. Please change the value of {0}") \
+ .format(frappe.bold(self.meta.get_field(field).label)), title =_("Incorrect Warehouse"))
+
def cant_change_valuation_method(self):
db_valuation_method = frappe.db.get_single_value("Stock Settings", "valuation_method")