Limiting User to one Warehouse; the warehouse not showed in link if input field is cleared

Hi there,

i’ve successfully limited user to one warehouse selection, see pic:

If user, for some reason, will clear the warehouse name from imput field; warehouse is not anymore showed in the link field, only Advanced Search appear, see pic:

Any hint?

Can you share custom script you are using to override the link query?

@revant_one I’ve applied on Stock Manager Role (the one applied to the user) for custom Cash Ward Refuse Doctype:

limited the Warehouse Doctype for the same rule:

and for particular user allowed only one warehouse:

the script i’ve used is to show only warehouse with is_group = 0:

frappe.ui.form.on("Cash Ward Refuse", "onload", function (frm) {
	cur_frm.set_query("warehouse", function () {
		return {
			"filters": {
				"is_group": "0"
			}
		};
	});
});

Btw i’ve commented out and i’m getting the same problem …

Can you try removing “Apply User Permissions” for “Stock User” on “Warehouse”?

Just the “Apply User Permission” check box?

Which Doctypes have you restricted warehouse by?

@revant_one it doesn’t work …it shows all warehouses, see pic:

Another little bug …the red border of the below input field overlap …

I faced similar situation, I wanted to restrict users to certain warehouses.

It works well for limiting access to PR or any DocType based on warehouse. When Warehouse are restricted only PRs with allowed warehouses are shown to user.

It is not limiting warehouses in link field. For this I used a workaround. Added Custom Link Field for Territory under Warehouse Doctype and set user restrictions for territories as well. This solved the problem for me.

So now Users are allowed to see those Warehouses for whose Territories are allowed.

I created a new group node for Warehouse Territories under Territory tree.

@revant_one thanks for the hint, what PR stands for?

Btw it would not work for us …we’ve 8 warehouse (stores) in the same city …so we need to limit access per user per warehouse.

It looks like a bug on the way links are working …i mean, link is limited correctly when the page is loaded (on load) …while when u delete the content of the search doesn’t show anymore the warehouse …

An workaround could be to have Warehouse field read only depending on user role …is that possible?

Honestly i’d prefer to have the link working as it’s supposed to be …

PR = Purchase Receipt

@revant_one thx …so tell me is this a bug? and i should open an issue on github?

I’ll try to explain case I dealt with, Multiple Warehouse per City.

Added Territories:

New Field on Warehouse

User Permissions:

Role Permissions :

User Sees only filtered warehouses,

2 Likes

@revant_one

thx to explain but i still think it’s a bug on the way link works …i shouldn’t need to add custom fields on warehouse to make it working …should work once role is set …and it works for on load document …

@revant_one

have a look at this:

Cash Ward is a custom doctype; applying same user permission as warehouse doctype …it works perfectly …it sound to me like a bug in the way warehouse link are displayed

@revant_one i finally made it work!!! it’s needed to add to the user permissions the full chain:

Company -> Warehouse Account -> Warehouse Group -> Warehouse in user permission

I think that’s related to the Tree organization of the Warehouses; it’s not quite straightforward and probably deserve a better docs.

3 Likes

Hi @JoEz
I was stuck with the same problem. Your solution helped me too!.
Although the only intended change I could see is where a list view is supposed to fetch warehouse names. Here only the warehouse permitted to the user is visible. This is off-course intended.

Further, I noticed that even if the access to a particular warehouse is restricted, the user is still able to see Material requests for other warehouses. What is strange is that the user can also make stock entries for material requests of a warehouse not permitted to the user.

Since “Source Warehouse”, “For Warehouse”, “Target Warehouse” are linked fields in all of the items the user should basically not be able to see any of these requests. I have made sure that the “Ignore User Permissions” check box in unchecked the Material Request and Material Request Item DocType.

i think u have to limit the Material role

Material Request did not have a linked field to warehouse. The linked field was in its child table Material Request Item. So I customized the form to add a hidden field of link type- pointing to the warehouse.

This way I could add the user permission “If Warehouse is permitted” to the Material Request DocType.

I need to Link the User for Default Warehouse. Anyone have any idea on this ?

Add a custom user permission

Can this solution be applied to a Role or Role Profile instead of a user?

This would make it easier for non-technical users to new users and assign similar permissions.