[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:
parent
06ef4270f2
commit
6ffdf94003
@ -7,9 +7,9 @@ frappe.treeview_settings["Account"] = {
|
|||||||
filters: [{
|
filters: [{
|
||||||
fieldname: "company",
|
fieldname: "company",
|
||||||
fieldtype:"Select",
|
fieldtype:"Select",
|
||||||
options: $.map(locals[':Company'], function(c) { return c.name; }).sort(),
|
options: erpnext.utils.get_tree_options("company"),
|
||||||
label: __("Company"),
|
label: __("Company"),
|
||||||
default: frappe.defaults.get_default('company') ? frappe.defaults.get_default('company'): ""
|
default: erpnext.utils.get_tree_default("company")
|
||||||
}],
|
}],
|
||||||
root_label: "Accounts",
|
root_label: "Accounts",
|
||||||
get_tree_nodes: 'erpnext.accounts.utils.get_children',
|
get_tree_nodes: 'erpnext.accounts.utils.get_children',
|
||||||
@ -42,6 +42,8 @@ frappe.treeview_settings["Account"] = {
|
|||||||
],
|
],
|
||||||
ignore_fields:["parent_account"],
|
ignore_fields:["parent_account"],
|
||||||
onload: function(treeview) {
|
onload: function(treeview) {
|
||||||
|
frappe.treeview_settings['Account'].page = {};
|
||||||
|
$.extend(frappe.treeview_settings['Account'].page, treeview.page);
|
||||||
function get_company() {
|
function get_company() {
|
||||||
return treeview.page.fields_dict.company.get_value();
|
return treeview.page.fields_dict.company.get_value();
|
||||||
}
|
}
|
||||||
@ -101,7 +103,7 @@ frappe.treeview_settings["Account"] = {
|
|||||||
"account": node.label,
|
"account": node.label,
|
||||||
"from_date": frappe.sys_defaults.year_start_date,
|
"from_date": frappe.sys_defaults.year_start_date,
|
||||||
"to_date": frappe.sys_defaults.year_end_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");
|
frappe.set_route("query-report", "General Ledger");
|
||||||
},
|
},
|
||||||
|
|||||||
@ -4,9 +4,9 @@ frappe.treeview_settings["Cost Center"] = {
|
|||||||
filters: [{
|
filters: [{
|
||||||
fieldname: "company",
|
fieldname: "company",
|
||||||
fieldtype:"Select",
|
fieldtype:"Select",
|
||||||
options: $.map(locals[':Company'], function(c) { return c.name; }).sort(),
|
options: erpnext.utils.get_tree_options("company"),
|
||||||
label: __("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",
|
root_label: "Cost Centers",
|
||||||
get_tree_nodes: 'erpnext.accounts.utils.get_children',
|
get_tree_nodes: 'erpnext.accounts.utils.get_children',
|
||||||
|
|||||||
@ -4,9 +4,9 @@ frappe.treeview_settings['Employee'] = {
|
|||||||
{
|
{
|
||||||
fieldname: "company",
|
fieldname: "company",
|
||||||
fieldtype:"Select",
|
fieldtype:"Select",
|
||||||
options: $.map(locals[':Company'], function(c) { return c.name; }).sort(),
|
options: erpnext.utils.get_tree_options("company"),
|
||||||
label: __("Company"),
|
label: __("Company"),
|
||||||
default: frappe.defaults.get_default('company') ? frappe.defaults.get_default('company') : ""
|
default: erpnext.utils.get_tree_default("company")
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
breadcrumb: "Hr",
|
breadcrumb: "Hr",
|
||||||
|
|||||||
@ -182,6 +182,25 @@ $.extend(erpnext.utils, {
|
|||||||
}
|
}
|
||||||
return rows;
|
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) {
|
erpnext.utils.select_alternate_items = function(opts) {
|
||||||
|
|||||||
@ -6,9 +6,9 @@ frappe.treeview_settings['Warehouse'] = {
|
|||||||
filters: [{
|
filters: [{
|
||||||
fieldname: "company",
|
fieldname: "company",
|
||||||
fieldtype:"Select",
|
fieldtype:"Select",
|
||||||
options: $.map(locals[':Company'], function(c) { return c.name; }).sort(),
|
options: erpnext.utils.get_tree_options("company"),
|
||||||
label: __("Company"),
|
label: __("Company"),
|
||||||
default: frappe.defaults.get_default('company') ? frappe.defaults.get_default('company'): ""
|
default: erpnext.utils.get_tree_default("company")
|
||||||
}],
|
}],
|
||||||
fields:[
|
fields:[
|
||||||
{fieldtype:'Data', fieldname: 'warehouse_name',
|
{fieldtype:'Data', fieldname: 'warehouse_name',
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user