Merge pull request #16738 from deepeshgarg007/unique_tree_options

fix: Filter out unique values for tree options
This commit is contained in:
Nabin Hait 2019-02-21 18:09:42 +05:30 committed by GitHub
commit e328869b10
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -255,11 +255,16 @@ $.extend(erpnext.utils, {
// get valid options for tree based on user permission & locals dict
let unscrub_option = frappe.model.unscrub(option);
let user_permission = frappe.defaults.get_user_permissions();
let options;
if(user_permission && user_permission[unscrub_option]) {
return user_permission[unscrub_option].map(perm => perm.doc);
options = user_permission[unscrub_option].map(perm => perm.doc);
} else {
return $.map(locals[`:${unscrub_option}`], function(c) { return c.name; }).sort();
options = $.map(locals[`:${unscrub_option}`], function(c) { return c.name; }).sort();
}
// filter unique values, as there may be multiple user permissions for any value
return options.filter((value, index, self) => self.indexOf(value) === index);
},
get_tree_default: function(option) {
// set default for a field based on user permission