mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-27 17:04:47 +00:00
fix: charts not displaying when tree_type changed
This commit is contained in:
@@ -75,62 +75,66 @@ frappe.query_reports["Purchase Analytics"] = {
|
|||||||
return Object.assign(options, {
|
return Object.assign(options, {
|
||||||
checkboxColumn: true,
|
checkboxColumn: true,
|
||||||
events: {
|
events: {
|
||||||
onCheckRow: function(data) {
|
onCheckRow: function (data) {
|
||||||
|
if (!data) return;
|
||||||
|
|
||||||
|
const data_doctype = $(
|
||||||
|
data[2].html
|
||||||
|
)[0].attributes.getNamedItem("data-doctype").value;
|
||||||
|
const tree_type = frappe.query_report.filters[0].value;
|
||||||
|
if (data_doctype != tree_type) return;
|
||||||
|
|
||||||
row_name = data[2].content;
|
row_name = data[2].content;
|
||||||
length = data.length;
|
length = data.length;
|
||||||
|
|
||||||
var tree_type = frappe.query_report.filters[0].value;
|
if (tree_type == "Supplier" || tree_type == "Item") {
|
||||||
|
row_values = data
|
||||||
if(tree_type == "Supplier" || tree_type == "Item") {
|
.slice(4, length - 1)
|
||||||
row_values = data.slice(4,length-1).map(function (column) {
|
.map(function (column) {
|
||||||
return column.content;
|
return column.content;
|
||||||
})
|
});
|
||||||
}
|
} else {
|
||||||
else {
|
row_values = data
|
||||||
row_values = data.slice(3,length-1).map(function (column) {
|
.slice(3, length - 1)
|
||||||
return column.content;
|
.map(function (column) {
|
||||||
})
|
return column.content;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
entry = {
|
entry = {
|
||||||
'name':row_name,
|
name: row_name,
|
||||||
'values':row_values
|
values: row_values,
|
||||||
}
|
};
|
||||||
|
|
||||||
let raw_data = frappe.query_report.chart.data;
|
let raw_data = frappe.query_report.chart.data;
|
||||||
let new_datasets = raw_data.datasets;
|
let new_datasets = raw_data.datasets;
|
||||||
|
|
||||||
var found = false;
|
let found = false;
|
||||||
|
|
||||||
for(var i=0; i < new_datasets.length;i++){
|
for (let i = 0; i < new_datasets.length; i++) {
|
||||||
if(new_datasets[i].name == row_name){
|
if (new_datasets[i].name == row_name) {
|
||||||
found = true;
|
found = true;
|
||||||
new_datasets.splice(i,1);
|
new_datasets.splice(i, 1);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!found){
|
if (!found) {
|
||||||
new_datasets.push(entry);
|
new_datasets.push(entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
let new_data = {
|
let new_data = {
|
||||||
labels: raw_data.labels,
|
labels: raw_data.labels,
|
||||||
datasets: new_datasets
|
datasets: new_datasets,
|
||||||
}
|
};
|
||||||
|
chart_options = {
|
||||||
setTimeout(() => {
|
data: new_data,
|
||||||
frappe.query_report.chart.update(new_data)
|
type: "line",
|
||||||
},500)
|
};
|
||||||
|
frappe.query_report.render_chart(chart_options);
|
||||||
|
|
||||||
setTimeout(() => {
|
|
||||||
frappe.query_report.chart.draw(true);
|
|
||||||
}, 1000)
|
|
||||||
|
|
||||||
frappe.query_report.raw_chart_data = new_data;
|
frappe.query_report.raw_chart_data = new_data;
|
||||||
},
|
},
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -74,67 +74,74 @@ frappe.query_reports["Sales Analytics"] = {
|
|||||||
return Object.assign(options, {
|
return Object.assign(options, {
|
||||||
checkboxColumn: true,
|
checkboxColumn: true,
|
||||||
events: {
|
events: {
|
||||||
onCheckRow: function(data) {
|
onCheckRow: function (data) {
|
||||||
|
if (!data) return;
|
||||||
|
|
||||||
|
const data_doctype = $(
|
||||||
|
data[2].html
|
||||||
|
)[0].attributes.getNamedItem("data-doctype").value;
|
||||||
|
const tree_type = frappe.query_report.filters[0].value;
|
||||||
|
if (data_doctype != tree_type) return;
|
||||||
|
|
||||||
row_name = data[2].content;
|
row_name = data[2].content;
|
||||||
length = data.length;
|
length = data.length;
|
||||||
|
|
||||||
var tree_type = frappe.query_report.filters[0].value;
|
if (tree_type == "Customer") {
|
||||||
|
row_values = data
|
||||||
if(tree_type == "Customer") {
|
.slice(4, length - 1)
|
||||||
row_values = data.slice(4,length-1).map(function (column) {
|
.map(function (column) {
|
||||||
return column.content;
|
return column.content;
|
||||||
})
|
});
|
||||||
} else if (tree_type == "Item") {
|
} else if (tree_type == "Item") {
|
||||||
row_values = data.slice(5,length-1).map(function (column) {
|
row_values = data
|
||||||
return column.content;
|
.slice(5, length - 1)
|
||||||
})
|
.map(function (column) {
|
||||||
}
|
return column.content;
|
||||||
else {
|
});
|
||||||
row_values = data.slice(3,length-1).map(function (column) {
|
} else {
|
||||||
return column.content;
|
row_values = data
|
||||||
})
|
.slice(3, length - 1)
|
||||||
|
.map(function (column) {
|
||||||
|
return column.content;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
entry = {
|
entry = {
|
||||||
'name':row_name,
|
name: row_name,
|
||||||
'values':row_values
|
values: row_values,
|
||||||
}
|
};
|
||||||
|
|
||||||
let raw_data = frappe.query_report.chart.data;
|
let raw_data = frappe.query_report.chart.data;
|
||||||
let new_datasets = raw_data.datasets;
|
let new_datasets = raw_data.datasets;
|
||||||
|
|
||||||
var found = false;
|
let found = false;
|
||||||
|
|
||||||
for(var i=0; i < new_datasets.length;i++){
|
for (let i = 0; i < new_datasets.length; i++) {
|
||||||
if(new_datasets[i].name == row_name){
|
if (new_datasets[i].name == row_name) {
|
||||||
found = true;
|
found = true;
|
||||||
new_datasets.splice(i,1);
|
new_datasets.splice(i, 1);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!found){
|
if (!found) {
|
||||||
new_datasets.push(entry);
|
new_datasets.push(entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
let new_data = {
|
let new_data = {
|
||||||
labels: raw_data.labels,
|
labels: raw_data.labels,
|
||||||
datasets: new_datasets
|
datasets: new_datasets,
|
||||||
}
|
};
|
||||||
|
chart_options = {
|
||||||
setTimeout(() => {
|
data: new_data,
|
||||||
frappe.query_report.chart.update(new_data)
|
type: "line",
|
||||||
}, 500)
|
};
|
||||||
|
frappe.query_report.render_chart(chart_options);
|
||||||
|
|
||||||
setTimeout(() => {
|
|
||||||
frappe.query_report.chart.draw(true);
|
|
||||||
}, 1000)
|
|
||||||
|
|
||||||
frappe.query_report.raw_chart_data = new_data;
|
frappe.query_report.raw_chart_data = new_data;
|
||||||
},
|
},
|
||||||
}
|
},
|
||||||
})
|
});
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user