fix: Server side validation for Warehouses

This commit is contained in:
marination 2020-02-19 11:05:58 +05:30
parent bde13b98e0
commit 120f75026f
2 changed files with 11 additions and 3 deletions

View File

@ -5,11 +5,11 @@ frappe.ui.form.on('Stock Settings', {
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);

View File

@ -30,9 +30,17 @@ class StockSettings(Document):
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")