Merge pull request #48226 from aerele/trends_reports

Trends reports
This commit is contained in:
ruthra kumar
2025-06-24 15:47:51 +05:30
committed by GitHub
4 changed files with 39 additions and 15 deletions

View File

@@ -24,22 +24,28 @@ def get_chart_data(data, conditions, filters):
datapoints = []
start = 3 if filters.get("based_on") in ["Item", "Supplier"] else 1
if filters.get("based_on") in ["Supplier"]:
start = 3
elif filters.get("based_on") in ["Item"]:
start = 2
else:
start = 1
if filters.get("group_by"):
start += 1
# fetch only periodic columns as labels
columns = conditions.get("columns")[start:-2][1::2]
columns = conditions.get("columns")[start:-2][2::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]:
if not row[start]:
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]
row = row[2::2]
for i in range(len(row)):
datapoints[i] += row[i]

View File

@@ -97,8 +97,10 @@ def get_data(filters, conditions):
elif filters.get("group_by") == "Supplier":
sel_col = "t1.supplier"
if filters.get("based_on") in ["Item", "Customer", "Supplier"]:
if filters.get("based_on") in ["Customer", "Supplier"]:
inc = 3
elif filters.get("based_on") in ["Item"]:
inc = 2
else:
inc = 1
@@ -158,7 +160,7 @@ def get_data(filters, conditions):
# get data for group_by filter
row1 = frappe.db.sql(
""" select t1.currency , {} , {} from `tab{}` t1, `tab{} Item` t2 {}
""" select t4.default_currency AS currency , {} , {} from `tab{}` t1, `tab{} Item` t2 {}
where t2.parent = t1.name and t1.company = {} and {} between {} and {}
and t1.docstatus = 1 and {} = {} and {} = {} {} {}
""".format(
@@ -392,8 +394,12 @@ def based_wise_columns_query(based_on, trans):
else:
frappe.throw(_("Project-wise data is not available for Quotation"))
based_on_details["based_on_select"] += "t1.currency,"
based_on_details["based_on_select"] += "t4.default_currency as currency,"
based_on_details["based_on_cols"].append("Currency:Link/Currency:120")
based_on_details["addl_tables"] += ", `tabCompany` t4"
based_on_details["addl_tables_relational_cond"] = (
based_on_details.get("addl_tables_relational_cond", "") + " and t1.company = t4.name"
)
return based_on_details

View File

@@ -25,22 +25,28 @@ def get_chart_data(data, conditions, filters):
datapoints = []
start = 3 if filters.get("based_on") in ["Item", "Customer"] else 1
if filters.get("based_on") in ["Customer"]:
start = 3
elif filters.get("based_on") in ["Item"]:
start = 2
else:
start = 1
if filters.get("group_by"):
start += 1
# fetch only periodic columns as labels
columns = conditions.get("columns")[start:-2][1::2]
columns = conditions.get("columns")[start:-2][2::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]:
if not row[start]:
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]
row = row[2::2]
for i in range(len(row)):
datapoints[i] += row[i]

View File

@@ -24,22 +24,28 @@ def get_chart_data(data, conditions, filters):
datapoints = []
start = 3 if filters.get("based_on") in ["Item", "Customer"] else 1
if filters.get("based_on") in ["Customer"]:
start = 3
elif filters.get("based_on") in ["Item"]:
start = 2
else:
start = 1
if filters.get("group_by"):
start += 1
# fetch only periodic columns as labels
columns = conditions.get("columns")[start:-2][1::2]
columns = conditions.get("columns")[start:-2][2::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]:
if not row[start]:
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]
row = row[2::2]
for i in range(len(row)):
datapoints[i] += row[i]