I want to restrict a users with respect to its Source warehouse and stock entry type using Custom doctype (Stock Entry Restriction) with Child table (Stock Entry Permission) .
If user saving form without using specific given validation , It should throw frappe.msgprint and frappe.throw
Custom doctype(Stock Entry Restriction)
I have applied this logic on client script :
frappe.ui.form.on(‘Stock Entry’, “validate”, function(frm) {
var email = frappe.session.user;
console.log(email);
frappe.model.with_doc('Stock Entry Restriction',frm.doc.validate,function(){
var table_info = frappe.model.get_doc('Stock Entry Restriction',frm.doc.validate);
console.log(table_info);
console.log(table_info.stock_entry_permission);
var users = table_info.stock_entry_permission;
for(var i=0;i<users.length;i++){
var user_mail = users[i].user;
var restrict_sw = users[i].source_warehouse;
var restrict_set = users[i].stock_entry_type;
console.log(user_mail);
if(email==user_mail && frm.doc.from_warehouse==restrict_sw && frm.doc.stock_entry_type == restrict_set){
console.log('success');
}
else{
console.log(restrict_sw);
frappe.validated = false;
frappe.msgprint(__('You are only allowed '));
frappe.throw(__('This is an Error Message'));
}
}
});
});
But it is only checking for 1st row of validation for specific user , what should i do ?
Should I make a list or dictionary for checking this validation Or else any other solution ?