Problem at stock entry

Dear All

I have a problem in stock Entry this screen Have Many Doc type (Material Transfer – Material Issue – Material Receipt – Material Transfer for Manufacture - Manufacture – Repack – Subcontract)

I need Permission at this doc type
I make Role permission (Material Transfer – Material Issue – Material Receipt – Material Transfer for Manufacture - Manufacture – Repack – Subcontract)
I do not want any user that can do any extra movement for conciliation vested in him

Thanks

not sure i understand what u mean …

I need make permission to users can’t make material transfer out role permission

huummm …that’s sound a contradiction …just dont give user permission

I need give user permission to make just material transfer and a another user make matreial issue , a another user make material receipt

U need to use User Permission Settings, but not sure if it works for Select Input type

Yes I need permission to type
Who I make role permission to make just matreial transfer

If you want to block specific users from creating/editing Stock Entry you need to do the following:

  • Go to Setup>User Permissions Manager (Or just type User Permissions Manager in the search box)
  • On the first field, pick a user. On the second drop-down/field for “Select Doctype” select the “Stock Entry”
  • Click the “Add a User Restriction” Button below the fields.

There’s also what you call a “Role Permissions Manager” which controls the access of all users with a specific role.
Eg. if User 1 and User 2 have the role “Stock Manager” and you changed Stock Manager so that he can’t edit Stock Entry, then both User 1 and User 2 won’t be able to edit Stock Entry.

Hope it helps.

thanks for answer me

this is not working you not under stand me i need permission at stock entry ( Purpose )


i need user make only material transfer
and user cant make material issue

Please check this for the reference.

https://frappe.github.io/erpnext/user/manual/en/customize-erpnext/custom-scripts/custom-script-examples/restrict-purpose-of-stock-entry

1 Like

thanks Mr umair

its not working

and i need permission at role not at user

thanks

The script provided was a sample script. You might have to refactor it to make it work as per your condition. Will be helpful if you have expertise in the JavA Script.

Share your code

MR : rohit_w
function my_before_submit(doc,cdt,cdn) {
$.each(cur_frm.doc.items || [], function(i, d) {
if(d.t_warehouse && (!d.target_locator || d.target_locator==“”)) {
validated = false;
msgprint(“Locator is not defined for target warehouse in row”+d.idx);
}
if(d.s_warehouse && (!d.locator || d.locator==“”)) {
validated = false;
msgprint(“Locator is not defined for source warehouse in row”+d.idx);
}
});
}
cur_frm.cscript.after_save = function(doc,cdt,cdn) {
validated = true;
cur_frm.doc.flg = 0;
$.each(cur_frm.doc.items || [], function(i, d) {
if(d.t_warehouse && (!d.target_locator || d.target_locator==“”)) {
cur_frm.call({
method: “frappe.client.get_value”,
args: {
doctype: “Locator”,
fieldname: “name”,
filters: { parent: d.t_warehouse },
},
callback: function(r, rt) {
if(r.message) {
validated = false;
cur_frm.doc.flg = -1;
msgprint(“Locator is not defined for target warehouse in row”+d.idx);
}
}
});
}
});
}
cur_frm.cscript.custom_s_warehouse = function(doc,cdt,cdn) {
d = locals[cdt][cdn];
hhh = frappe.call({
method:“frappe.direction.customizations.get_default_locator”,
args: {warehouse: d.s_warehouse},
callback: function(r,rt) {
if(!r.exc && r.message[0].loc>=1) {
d.locator = r.message[0].locator;
refresh_field(‘locator’,d.name,‘items’);
} else {
d.locator = “”;
refresh_field(“locator”,d.name,“items”);
}
}
});
}
cur_frm.cscript.custom_t_warehouse = function(doc,cdt,cdn) {
d = locals[cdt][cdn];
hhh = frappe.call({
method:“frappe.direction.customizations.get_default_locator”,
args: {warehouse: d.t_warehouse},
callback: function(r,rt) {
if(!r.exc && r.message[0].loc>=1) {
d.target_locator = r.message[0].locator;
refresh_field(‘target_locator’,d.name,‘items’);
} else {
d.target_locator = “”;
refresh_field(“target_locator”,d.name,“items”);
}
}
});
}
cur_frm.cscript.before_submit = function(doc,cdt,cdn) {
my_before_submit();
if (cur_frm.doc.flg<2 && cur_frm.doc.flg>=0) {
cur_frm.doc.flg = 0;
validated = false;
}
if (cur_frm.doc.flg==-1) {
validated = false;
msgprint(“Did Not Save \nUndefined locator !!!”);
} else {
$.each(cur_frm.doc.items || [], function(i, d) {
if(d.s_warehouse) {
hhh = frappe.call({
method:“frappe.direction.customizations.check_locator_bal”,
args: {item_code: d.item_code, warehouse: d.s_warehouse, locator: d.locator || “xxx”, qty: d.qty},
callback: function(r,rt) {
if(!r.exc && r.message[0].flg<0) {
cur_frm.doc.flg = 1;
validated = false;
th_msg = “item: ”+r.message[0].item_code+“ | “;
th_msg += “warehouse: ”+r.message[0].warehouse+” | “;
th_msg += “locator: ”+r.message[0].locator+”\n Have Quantity: ”+r.message[0].qty;
th_msg += “
less than quantity entered in Row# ”+d.idx.toString()+“”;
//cur_frm.disable_save();
frappe.throw(th_msg);
//msgprint(th_msg);
}
if((!r.exc) && cur_frm.doc.flg!=1 && r.message[0].flg>=0) {
cur_frm.doc.flg = 2;
if(d.length==d.idx) {
validated = true;
cur_frm.save(“Submit”);
}
}
}
});
}
else {
if(cur_frm.doc.flg!=-1) {
cur_frm.doc.flg = 2;
validated = true;
cur_frm.save(“Submit”);
}
}
});
}
}
cur_frm.fields_dict[‘items’].grid.get_field(‘locator’).get_query = function(doc, cdt, cdn) {
var item = locals[cdt][cdn];
if(!item.item_code) {
frappe.throw(__(“Please enter Item Code to get Warehouses”));
}
else {
var filters = {
‘item_code’: item.item_code,
‘warehouse’: item.s_warehouse
}

	return {
		query : "frappe.direction.customizations.locator_query",
		filters: filters
	}
}

}
cur_frm.fields_dict[‘items’].grid.get_field(‘target_locator’).get_query = function(doc, cdt, cdn) {
var item = locals[cdt][cdn];
return {
filters: {‘parent’: item.t_warehouse}
}
}
cur_frm.cscript.custom_onload = function(doc,cdt,cdn) {
cur_frm.get_field(‘items’).grid.editable_fields = [
{fieldname: ‘item_code’, columns: 2},
{fieldname: ‘item_name’, columns: 2},
{fieldname: ‘qty’, columns: 2},
{fieldname: ‘s_warehouse’, columns: 2},
{fieldname: ‘t_warehouse’, columns: 2}
];
}
// Fix empty locator after selecting an item
frappe.ui.form.on(“Stock Entry Detail”, {
“item_code”: function(doc, cdt, cdn) {
var d = locals[cdt][cdn];
var isDone=false;
$(document).ajaxStop(function() {
if(isDone)return;
isDone=true;
if (d.s_warehouse) {
//alert(d.warehouse);
cur_frm.cscript.custom_s_warehouse(doc, cdt, cdn);
}
if (d.t_warehouse) {
//alert(d.warehouse);
cur_frm.cscript.custom_t_warehouse(doc, cdt, cdn);
}
frappe.ui.form.on(“Material Request”, “validate”, function(frm) {
if(user=="test1@gmail.com" && frm.doc.purpose!=“Material Receipt”) {
msgprint(“You are only allowed Material Receipt”);
throw “Not allowed”;
}
}
});
}
});

Hi @Sherif_Mohamed_Ismai

Did you made changes in the core file? Make custom script and add code to restrict users. Refer below code, and make changes according to your requirement

frappe.ui.form.on("Stock Entry", "validate", function(frm) {
    if(user=="put user name" && frm.doc.purpose!="Material Receipt") {
        msgprint("You are only allowed Material Receipt");
        throw "Not allowed";
    }
}
1 Like

What role do you currently have in your ERPNext instance? Can you access an Administrator account? If you can, try going to Users and click on your email and assign the role to your account which has the permissions that you need. If not try going to Role Permissions, pick your current role and doctype, and check the checkboxes for creating/editing, viewing, save, submit and any other stuff you might need.

Hope it helps.

1 Like

HI @umair this link is not working anymore. Can you please share this again.

Found it. Thanks