Actually we want validation in server script, but we don’t familiar where such type of coding should be done in the erpnext ?
So kindly guide us on how shall we write the validation code as our below requirement details.
if a user has not allowed the role of " System Manager " then,we need to stop or validate that target warehouse should not be ( “CANTEEN SHANTIKUNJ (Production) 30121 - UK-TMD”, “CANTEEN SRIRAM PURAM (Production) 30121 - UK-TMD”, “CANTEEN GAYATRIKUNJ (Production) 30121 - UK-TMD”, “JAL PAN GRUH RAW MATERIAL - UK-TMD” ) . When processing it from " stock summary " for transferring or moving the stock from the source into target warehouse(sale counter).
Code:
where should we write this code properly?
i=0
roles = frappe.get_all(“Has Role”, fields = [“role”], filters={“parent”: frappe.session.user, “role”: (“not in”, [“All”, “Guest”])})
user_roles = [r.role for r in roles]
warehouse_list = [“CANTEEN SHANTIKUNJ (Production) 30121 - UK-TMD”,
“CANTEEN SRIRAM PURAM (Production) 30121 - UK-TMD”, “CANTEEN GAYATRIKUNJ (Production) 30121 - UK-TMD”,
“JAL PAN GRUH RAW MATERIAL - UK-TMD”]
while i < len(doc.items):
if “System Manager” not in user_roles and doc.items[i].t_warehouse in warehouse_list:
msg = "You don’t have permission to make stock transfer entry against warehouse: " + doc.items[i].t_warehouse
frappe.msgprint(msg, raise_exception=True)
i = i + 1
Thanks and Regards,
Shivam Shukla