fix: Server side validation for Warehouses
This commit is contained in:
parent
bde13b98e0
commit
120f75026f
@ -5,11 +5,11 @@ frappe.ui.form.on('Stock Settings', {
|
|||||||
refresh: function(frm) {
|
refresh: function(frm) {
|
||||||
let filters = function() {
|
let filters = function() {
|
||||||
return {
|
return {
|
||||||
filters : {
|
filters : {
|
||||||
is_group : 0
|
is_group : 0
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
};
|
||||||
|
|
||||||
frm.set_query("default_warehouse", filters);
|
frm.set_query("default_warehouse", filters);
|
||||||
frm.set_query("sample_retention_warehouse", filters);
|
frm.set_query("sample_retention_warehouse", filters);
|
||||||
|
|||||||
@ -30,9 +30,17 @@ class StockSettings(Document):
|
|||||||
frappe.make_property_setter({'fieldname': name, 'property': 'hidden',
|
frappe.make_property_setter({'fieldname': name, 'property': 'hidden',
|
||||||
'value': 0 if self.show_barcode_field else 1})
|
'value': 0 if self.show_barcode_field else 1})
|
||||||
|
|
||||||
|
self.validate_warehouses()
|
||||||
self.cant_change_valuation_method()
|
self.cant_change_valuation_method()
|
||||||
self.validate_clean_description_html()
|
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):
|
def cant_change_valuation_method(self):
|
||||||
db_valuation_method = frappe.db.get_single_value("Stock Settings", "valuation_method")
|
db_valuation_method = frappe.db.get_single_value("Stock Settings", "valuation_method")
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user