[Fixes] Defaults and User-Permission based fixes in treeview (#14501)

* utility function added for treeview
function to distinguish defaults from user permission and return appropriate data

* make use of utility function for treeview
This commit is contained in:
Zarrar 2018-06-14 12:24:16 +05:30 committed by Nabin Hait
parent 06ef4270f2
commit 6ffdf94003
5 changed files with 30 additions and 9 deletions

View File

@ -7,9 +7,9 @@ frappe.treeview_settings["Account"] = {
filters: [{
fieldname: "company",
fieldtype:"Select",
options: $.map(locals[':Company'], function(c) { return c.name; }).sort(),
options: erpnext.utils.get_tree_options("company"),
label: __("Company"),
default: frappe.defaults.get_default('company') ? frappe.defaults.get_default('company'): ""
default: erpnext.utils.get_tree_default("company")
}],
root_label: "Accounts",
get_tree_nodes: 'erpnext.accounts.utils.get_children',
@ -42,6 +42,8 @@ frappe.treeview_settings["Account"] = {
],
ignore_fields:["parent_account"],
onload: function(treeview) {
frappe.treeview_settings['Account'].page = {};
$.extend(frappe.treeview_settings['Account'].page, treeview.page);
function get_company() {
return treeview.page.fields_dict.company.get_value();
}
@ -101,7 +103,7 @@ frappe.treeview_settings["Account"] = {
"account": node.label,
"from_date": frappe.sys_defaults.year_start_date,
"to_date": frappe.sys_defaults.year_end_date,
"company": frappe.defaults.get_default('company') ? frappe.defaults.get_default('company'): ""
"company": frappe.treeview_settings['Account'].page.fields_dict.company.get_value()
};
frappe.set_route("query-report", "General Ledger");
},

View File

@ -4,9 +4,9 @@ frappe.treeview_settings["Cost Center"] = {
filters: [{
fieldname: "company",
fieldtype:"Select",
options: $.map(locals[':Company'], function(c) { return c.name; }).sort(),
options: erpnext.utils.get_tree_options("company"),
label: __("Company"),
default: frappe.defaults.get_default('company') ? frappe.defaults.get_default('company'): ""
default: erpnext.utils.get_tree_default("company")
}],
root_label: "Cost Centers",
get_tree_nodes: 'erpnext.accounts.utils.get_children',

View File

@ -4,9 +4,9 @@ frappe.treeview_settings['Employee'] = {
{
fieldname: "company",
fieldtype:"Select",
options: $.map(locals[':Company'], function(c) { return c.name; }).sort(),
options: erpnext.utils.get_tree_options("company"),
label: __("Company"),
default: frappe.defaults.get_default('company') ? frappe.defaults.get_default('company') : ""
default: erpnext.utils.get_tree_default("company")
}
],
breadcrumb: "Hr",

View File

@ -182,6 +182,25 @@ $.extend(erpnext.utils, {
}
return rows;
},
get_tree_options: function(option) {
// 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();
if(user_permission && user_permission[unscrub_option]) {
return user_permission[unscrub_option]["docs"];
} else {
return $.map(locals[`:${unscrub_option}`], function(c) { return c.name; }).sort();
}
},
get_tree_default: function(option) {
// set default for a field based on user permission
let options = this.get_tree_options(option);
if(options.includes(frappe.defaults.get_default(option))) {
return frappe.defaults.get_default(option);
} else {
return options[0];
}
}
});
erpnext.utils.select_alternate_items = function(opts) {

View File

@ -6,9 +6,9 @@ frappe.treeview_settings['Warehouse'] = {
filters: [{
fieldname: "company",
fieldtype:"Select",
options: $.map(locals[':Company'], function(c) { return c.name; }).sort(),
options: erpnext.utils.get_tree_options("company"),
label: __("Company"),
default: frappe.defaults.get_default('company') ? frappe.defaults.get_default('company'): ""
default: erpnext.utils.get_tree_default("company")
}],
fields:[
{fieldtype:'Data', fieldname: 'warehouse_name',