When the user chandanatest143@gmail.com logs in and tries to open the Company doctype, an error message appears saying “Insufficient Permission for Read.” I set the necessary permissions for that role, but the error still shows up.
The user chandanatest143@gmail.com have only access 1 company (Pazheri Test Company) but showing another company name (FIX) below is the screenshot of user permission
frappe.ui.form.on('Purchase Invoice', {
setup: function(frm) {
// Get the default company from the global defaults
let default_company = frappe.defaults.get_default('company');
// Fetch the list of companies the user has access to
frappe.call({
method: 'frappe.client.get_list',
args: {
doctype: 'Company',
pluck: 'name'
},
callback: function(r) {
if (r.message) {
let user_companies = r.message;
// Check if the user has access to the default company
if (!user_companies.includes(default_company)) {
// If the default company is not in the user's access list, change it to the first available company
let accessible_company = user_companies[0];
if (accessible_company) {
frm.set_value('company', accessible_company);
}
}
}
}
});
}
});