2013-11-20 07:29:58 +00:00
|
|
|
// Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
|
2013-08-05 09:29:54 +00:00
|
|
|
// License: GNU General Public License v3. See license.txt
|
2012-02-23 07:05:32 +00:00
|
|
|
|
2012-04-17 07:10:37 +00:00
|
|
|
pscript['onload_Sales Browser'] = function(wrapper){
|
2015-01-01 10:29:34 +00:00
|
|
|
var page = frappe.ui.make_app_page({
|
2013-05-23 10:33:49 +00:00
|
|
|
parent: wrapper,
|
2015-01-01 07:19:18 +00:00
|
|
|
single_column: true,
|
2015-01-01 10:29:34 +00:00
|
|
|
});
|
2014-04-22 13:24:54 +00:00
|
|
|
|
2014-12-19 10:50:32 +00:00
|
|
|
frappe.add_breadcrumbs("Selling")
|
2014-04-22 13:24:54 +00:00
|
|
|
|
2015-01-01 10:29:34 +00:00
|
|
|
wrapper.page.set_secondary_action(__('Refresh'), function() {
|
2012-04-17 07:10:37 +00:00
|
|
|
wrapper.make_tree();
|
2013-11-13 11:25:38 +00:00
|
|
|
});
|
2012-04-17 07:10:37 +00:00
|
|
|
|
|
|
|
wrapper.make_tree = function() {
|
2014-02-14 10:17:51 +00:00
|
|
|
var ctype = frappe.get_route()[1] || 'Territory';
|
|
|
|
return frappe.call({
|
2013-12-12 13:42:19 +00:00
|
|
|
method: 'erpnext.selling.page.sales_browser.sales_browser.get_children',
|
2012-12-12 10:56:39 +00:00
|
|
|
args: {ctype: ctype},
|
|
|
|
callback: function(r) {
|
|
|
|
var root = r.message[0]["value"];
|
2015-01-01 10:29:34 +00:00
|
|
|
erpnext.sales_chart = new erpnext.SalesChart(ctype, root, page,
|
2013-05-23 10:33:49 +00:00
|
|
|
$(wrapper)
|
|
|
|
.find(".layout-main-section")
|
|
|
|
.css({
|
|
|
|
"min-height": "300px",
|
|
|
|
"padding-bottom": "25px"
|
|
|
|
}));
|
2012-12-12 10:56:39 +00:00
|
|
|
}
|
|
|
|
});
|
2012-04-17 07:10:37 +00:00
|
|
|
}
|
2014-04-22 13:24:54 +00:00
|
|
|
|
2012-04-17 07:10:37 +00:00
|
|
|
wrapper.make_tree();
|
|
|
|
}
|
|
|
|
|
|
|
|
pscript['onshow_Sales Browser'] = function(wrapper){
|
|
|
|
// set route
|
2014-02-14 10:17:51 +00:00
|
|
|
var ctype = frappe.get_route()[1] || 'Territory';
|
2012-07-12 04:24:43 +00:00
|
|
|
|
2014-12-23 12:26:47 +00:00
|
|
|
wrapper.page.set_title(__('{0} Tree',[__(ctype)]));
|
2012-04-17 07:10:37 +00:00
|
|
|
|
|
|
|
if(erpnext.sales_chart && erpnext.sales_chart.ctype != ctype) {
|
|
|
|
wrapper.make_tree();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
erpnext.SalesChart = Class.extend({
|
2015-01-01 10:29:34 +00:00
|
|
|
init: function(ctype, root, page, parent) {
|
2013-05-23 10:33:49 +00:00
|
|
|
$(parent).empty();
|
2012-04-17 07:10:37 +00:00
|
|
|
var me = this;
|
|
|
|
me.ctype = ctype;
|
2015-01-01 10:29:34 +00:00
|
|
|
me.page = page;
|
2014-02-19 07:13:16 +00:00
|
|
|
me.can_read = frappe.model.can_read(this.ctype);
|
2014-03-11 10:45:05 +00:00
|
|
|
me.can_create = frappe.boot.user.can_create.indexOf(this.ctype) !== -1 ||
|
|
|
|
frappe.boot.user.in_create.indexOf(this.ctype) !== -1;
|
2014-02-19 07:13:16 +00:00
|
|
|
me.can_write = frappe.model.can_write(this.ctype);
|
|
|
|
me.can_delete = frappe.model.can_delete(this.ctype);
|
2014-04-22 13:24:54 +00:00
|
|
|
|
2015-01-01 10:29:34 +00:00
|
|
|
me.page.set_primary_action(__("New"), function() {
|
|
|
|
me.new_node();
|
|
|
|
});
|
|
|
|
|
2014-02-14 10:17:51 +00:00
|
|
|
this.tree = new frappe.ui.Tree({
|
2014-04-22 13:24:54 +00:00
|
|
|
parent: $(parent),
|
2014-09-10 07:36:53 +00:00
|
|
|
label: __(root),
|
2012-04-17 07:10:37 +00:00
|
|
|
args: {ctype: ctype},
|
2013-12-12 13:42:19 +00:00
|
|
|
method: 'erpnext.selling.page.sales_browser.sales_browser.get_children',
|
2014-02-19 07:13:16 +00:00
|
|
|
toolbar: [
|
|
|
|
{toggle_btn: true},
|
|
|
|
{
|
2014-04-22 13:24:54 +00:00
|
|
|
label:__("Edit"),
|
|
|
|
condition: function(node) {
|
2014-02-19 07:13:16 +00:00
|
|
|
return !node.root && me.can_read;
|
|
|
|
},
|
|
|
|
click: function(node) {
|
|
|
|
frappe.set_route("Form", me.ctype, node.label);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label:__("Add Child"),
|
|
|
|
condition: function(node) { return me.can_create && node.expandable; },
|
|
|
|
click: function(node) {
|
|
|
|
me.new_node();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label:__("Rename"),
|
|
|
|
condition: function(node) { return !node.root && me.can_write; },
|
|
|
|
click: function(node) {
|
|
|
|
frappe.model.rename_doc(me.ctype, node.label, function(new_name) {
|
|
|
|
node.$a.html(new_name);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label:__("Delete"),
|
|
|
|
condition: function(node) { return !node.root && me.can_delete; },
|
|
|
|
click: function(node) {
|
|
|
|
frappe.model.delete_doc(me.ctype, node.label, function() {
|
|
|
|
node.parent.remove();
|
|
|
|
});
|
|
|
|
}
|
2012-04-17 07:10:37 +00:00
|
|
|
}
|
2014-04-22 13:24:54 +00:00
|
|
|
|
2014-02-19 07:13:16 +00:00
|
|
|
]
|
2012-04-17 07:10:37 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
new_node: function() {
|
|
|
|
var me = this;
|
2015-01-01 10:29:34 +00:00
|
|
|
var node = me.tree.get_selected_node();
|
|
|
|
|
|
|
|
if(!(node && node.expandable)) {
|
|
|
|
frappe.msgprint(__("Select a group node first."));
|
|
|
|
return;
|
|
|
|
}
|
2014-04-22 13:24:54 +00:00
|
|
|
|
2013-07-22 11:45:01 +00:00
|
|
|
var fields = [
|
2014-04-22 13:24:54 +00:00
|
|
|
{fieldtype:'Data', fieldname: 'name_field',
|
2014-09-11 00:37:49 +00:00
|
|
|
label:__('New {0} Name',[__(me.ctype)]), reqd:true},
|
2014-09-10 07:36:53 +00:00
|
|
|
{fieldtype:'Select', fieldname:'is_group', label:__('Group Node'), options:'No\nYes',
|
2015-01-01 07:19:18 +00:00
|
|
|
description: __("Further nodes can be only created under 'Group' type nodes")}
|
2013-07-22 11:45:01 +00:00
|
|
|
]
|
2014-04-22 13:24:54 +00:00
|
|
|
|
2013-07-22 11:45:01 +00:00
|
|
|
if(me.ctype == "Sales Person") {
|
2014-09-10 07:36:53 +00:00
|
|
|
fields.splice(-1, 0, {fieldtype:'Link', fieldname:'employee', label:__('Employee'),
|
2014-04-14 10:55:30 +00:00
|
|
|
options:'Employee', description: __("Please enter Employee Id of this sales parson")});
|
2013-07-22 11:45:01 +00:00
|
|
|
}
|
2014-04-22 13:24:54 +00:00
|
|
|
|
2012-04-17 07:10:37 +00:00
|
|
|
// the dialog
|
2014-02-14 10:17:51 +00:00
|
|
|
var d = new frappe.ui.Dialog({
|
2014-09-10 07:36:53 +00:00
|
|
|
title: __('New {0}',[__(me.ctype)]),
|
2013-07-22 11:45:01 +00:00
|
|
|
fields: fields
|
2014-04-22 13:24:54 +00:00
|
|
|
})
|
|
|
|
|
2012-12-06 06:39:52 +00:00
|
|
|
d.set_value("is_group", "No");
|
2012-04-17 07:10:37 +00:00
|
|
|
// create
|
2015-01-01 07:19:18 +00:00
|
|
|
d.set_primary_action(__("Create New"), function() {
|
2012-04-17 07:10:37 +00:00
|
|
|
var btn = this;
|
|
|
|
var v = d.get_values();
|
|
|
|
if(!v) return;
|
2014-04-22 13:24:54 +00:00
|
|
|
|
2014-02-19 07:13:16 +00:00
|
|
|
var node = me.tree.get_selected_node();
|
2014-04-22 13:24:54 +00:00
|
|
|
|
2014-02-19 07:13:16 +00:00
|
|
|
v.parent = node.label;
|
2012-04-17 07:10:37 +00:00
|
|
|
v.ctype = me.ctype;
|
2014-04-22 13:24:54 +00:00
|
|
|
|
2014-02-14 10:17:51 +00:00
|
|
|
return frappe.call({
|
2013-12-12 13:42:19 +00:00
|
|
|
method: 'erpnext.selling.page.sales_browser.sales_browser.add_node',
|
2012-04-17 07:10:37 +00:00
|
|
|
args: v,
|
2014-03-06 09:15:02 +00:00
|
|
|
callback: function(r) {
|
|
|
|
if(!r.exc) {
|
|
|
|
d.hide();
|
2014-05-27 09:52:04 +00:00
|
|
|
if(node.expanded) {
|
2014-03-06 09:15:02 +00:00
|
|
|
node.toggle_node();
|
|
|
|
}
|
2014-05-27 09:52:04 +00:00
|
|
|
node.reload();
|
2014-03-06 09:15:02 +00:00
|
|
|
}
|
2014-04-22 13:24:54 +00:00
|
|
|
}
|
|
|
|
});
|
2012-04-17 07:10:37 +00:00
|
|
|
});
|
2015-01-01 07:19:18 +00:00
|
|
|
|
2014-04-22 13:24:54 +00:00
|
|
|
d.show();
|
2012-04-17 07:10:37 +00:00
|
|
|
},
|
2014-04-22 13:24:54 +00:00
|
|
|
});
|