mirror of
https://github.com/frappe/erpnext.git
synced 2026-02-13 09:43:49 +00:00
fix(sales analytics): add curve filter
This commit is contained in:
@@ -73,6 +73,18 @@ frappe.query_reports["Sales Analytics"] = {
|
||||
default: "Monthly",
|
||||
reqd: 1,
|
||||
},
|
||||
{
|
||||
fieldname: "curves",
|
||||
label: __("Curves"),
|
||||
fieldtype: "Select",
|
||||
options: [
|
||||
{ value: "all", label: __("All") },
|
||||
{ value: "non-zeros", label: __("Non-Zeros") },
|
||||
{ value: "total", label: __("Total Only") },
|
||||
],
|
||||
default: "all",
|
||||
reqd: 1,
|
||||
},
|
||||
{
|
||||
fieldname: "show_aggregate_value_from_subsidiary_companies",
|
||||
label: __("Show Aggregate Value from Subsidiary Companies"),
|
||||
|
||||
@@ -460,7 +460,31 @@ class Analytics:
|
||||
labels = [d.get("label") for d in self.columns[3 : length - 1]]
|
||||
else:
|
||||
labels = [d.get("label") for d in self.columns[1 : length - 1]]
|
||||
self.chart = {"data": {"labels": labels, "datasets": []}, "type": "line"}
|
||||
|
||||
datasets = []
|
||||
for curve in self.data:
|
||||
data = {
|
||||
"name": curve.get("entity_name", curve["entity"]),
|
||||
"values": [curve.get(scrub(label), 0) for label in labels],
|
||||
}
|
||||
if self.filters.curves == "non-zeros" and not sum(data["values"]):
|
||||
continue
|
||||
elif self.filters.curves == "total" and "indent" in curve:
|
||||
if curve["indent"] == 0:
|
||||
datasets.append(data)
|
||||
elif self.filters.curves == "total":
|
||||
if datasets:
|
||||
a = [
|
||||
data["values"][idx] + datasets[0]["values"][idx] for idx in range(len(data["values"]))
|
||||
]
|
||||
datasets[0]["values"] = a
|
||||
else:
|
||||
datasets.append(data)
|
||||
datasets[0]["name"] = _("Total")
|
||||
else:
|
||||
datasets.append(data)
|
||||
|
||||
self.chart = {"data": {"labels": labels, "datasets": datasets}, "type": "line"}
|
||||
|
||||
if self.filters["value_quantity"] == "Value":
|
||||
self.chart["fieldtype"] = "Currency"
|
||||
|
||||
Reference in New Issue
Block a user