2015-03-03 09:25:30 +00:00
|
|
|
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
|
2013-08-05 09:29:54 +00:00
|
|
|
# License: GNU General Public License v3. See license.txt
|
2013-06-07 12:35:16 +00:00
|
|
|
|
2021-09-02 11:14:59 +00:00
|
|
|
|
2020-06-19 10:03:21 +00:00
|
|
|
from frappe import _
|
2021-09-02 11:14:59 +00:00
|
|
|
|
2013-12-12 13:42:19 +00:00
|
|
|
from erpnext.controllers.trends import get_columns, get_data
|
2021-09-02 11:14:59 +00:00
|
|
|
|
2013-06-07 12:35:16 +00:00
|
|
|
|
|
|
|
def execute(filters=None):
|
|
|
|
if not filters:
|
|
|
|
filters = {}
|
2013-06-13 13:47:56 +00:00
|
|
|
data = []
|
2013-06-28 04:39:46 +00:00
|
|
|
conditions = get_columns(filters, "Quotation")
|
2013-06-20 13:22:31 +00:00
|
|
|
data = get_data(filters, conditions)
|
2013-06-14 09:33:45 +00:00
|
|
|
|
2020-06-19 10:03:21 +00:00
|
|
|
chart_data = get_chart_data(data, conditions, filters)
|
|
|
|
|
|
|
|
return conditions["columns"], data, None, chart_data
|
|
|
|
|
2022-03-28 13:22:46 +00:00
|
|
|
|
2020-06-19 10:03:21 +00:00
|
|
|
def get_chart_data(data, conditions, filters):
|
|
|
|
if not (data and conditions):
|
|
|
|
return []
|
|
|
|
|
|
|
|
datapoints = []
|
|
|
|
|
|
|
|
start = 2 if filters.get("based_on") in ["Item", "Customer"] else 1
|
|
|
|
if filters.get("group_by"):
|
|
|
|
start += 1
|
|
|
|
|
|
|
|
# fetch only periodic columns as labels
|
|
|
|
columns = conditions.get("columns")[start:-2][1::2]
|
|
|
|
labels = [column.split(":")[0] for column in columns]
|
|
|
|
datapoints = [0] * len(labels)
|
|
|
|
|
|
|
|
for row in data:
|
|
|
|
# If group by filter, don't add first row of group (it's already summed)
|
|
|
|
if not row[start - 1]:
|
|
|
|
continue
|
|
|
|
# Remove None values and compute only periodic data
|
|
|
|
row = [x if x else 0 for x in row[start:-2]]
|
|
|
|
row = row[1::2]
|
|
|
|
|
|
|
|
for i in range(len(row)):
|
|
|
|
datapoints[i] += row[i]
|
|
|
|
|
|
|
|
return {
|
|
|
|
"data": {
|
|
|
|
"labels": labels,
|
|
|
|
"datasets": [
|
2022-04-02 11:26:59 +00:00
|
|
|
{"name": _(filters.get("period")) + " " + _("Quoted Amount"), "values": datapoints}
|
2020-06-19 10:03:21 +00:00
|
|
|
],
|
|
|
|
},
|
|
|
|
"type": "line",
|
|
|
|
"lineOptions": {"regionFill": 1},
|
2022-05-10 09:55:08 +00:00
|
|
|
"fieldtype": "Currency",
|
2020-06-19 10:03:21 +00:00
|
|
|
}
|