mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-15 11:09:17 +00:00
refactor: sales analytics
This commit is contained in:
@@ -82,62 +82,42 @@ frappe.query_reports["Sales Analytics"] = {
|
|||||||
const tree_type = frappe.query_report.filters[0].value;
|
const tree_type = frappe.query_report.filters[0].value;
|
||||||
if (data_doctype != tree_type) return;
|
if (data_doctype != tree_type) return;
|
||||||
|
|
||||||
row_name = data[2].content;
|
const row_name = data[2].content;
|
||||||
length = data.length;
|
const raw_data = frappe.query_report.chart.data;
|
||||||
|
const new_datasets = raw_data.datasets;
|
||||||
if (tree_type == "Customer") {
|
const element_found = new_datasets.some(
|
||||||
row_values = data
|
(element, index, array) => {
|
||||||
.slice(4, length - 1)
|
if (element.name == row_name) {
|
||||||
.map(function (column) {
|
array.splice(index, 1);
|
||||||
return column.content;
|
return true;
|
||||||
});
|
}
|
||||||
} else if (tree_type == "Item") {
|
return false;
|
||||||
row_values = data
|
|
||||||
.slice(5, length - 1)
|
|
||||||
.map(function (column) {
|
|
||||||
return column.content;
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
row_values = data
|
|
||||||
.slice(3, length - 1)
|
|
||||||
.map(function (column) {
|
|
||||||
return column.content;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
entry = {
|
|
||||||
name: row_name,
|
|
||||||
values: row_values,
|
|
||||||
};
|
|
||||||
|
|
||||||
let raw_data = frappe.query_report.chart.data;
|
|
||||||
let new_datasets = raw_data.datasets;
|
|
||||||
|
|
||||||
let element_found = new_datasets.some((element, index, array)=>{
|
|
||||||
if(element.name == row_name){
|
|
||||||
array.splice(index, 1)
|
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
return false
|
);
|
||||||
})
|
const slice_at = { Customer: 4, Item: 5 }[tree_type] || 3;
|
||||||
|
|
||||||
if (!element_found) {
|
if (!element_found) {
|
||||||
new_datasets.push(entry);
|
new_datasets.push({
|
||||||
|
name: row_name,
|
||||||
|
values: data
|
||||||
|
.slice(slice_at, data.length - 1)
|
||||||
|
.map(column => column.content),
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
let new_data = {
|
const new_data = {
|
||||||
labels: raw_data.labels,
|
labels: raw_data.labels,
|
||||||
datasets: new_datasets,
|
datasets: new_datasets,
|
||||||
};
|
};
|
||||||
chart_options = {
|
|
||||||
|
frappe.query_report.render_chart({
|
||||||
data: new_data,
|
data: new_data,
|
||||||
type: "line",
|
type: "line",
|
||||||
};
|
});
|
||||||
frappe.query_report.render_chart(chart_options);
|
|
||||||
|
|
||||||
frappe.query_report.raw_chart_data = new_data;
|
frappe.query_report.raw_chart_data = new_data;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
}
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user