diff --git a/erpnext/buying/report/purchase_order_trends/purchase_order_trends.py b/erpnext/buying/report/purchase_order_trends/purchase_order_trends.py index 7398bb28736..a7b4a7207c6 100644 --- a/erpnext/buying/report/purchase_order_trends/purchase_order_trends.py +++ b/erpnext/buying/report/purchase_order_trends/purchase_order_trends.py @@ -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] diff --git a/erpnext/controllers/trends.py b/erpnext/controllers/trends.py index 57edae7053a..f5046bb4c67 100644 --- a/erpnext/controllers/trends.py +++ b/erpnext/controllers/trends.py @@ -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 diff --git a/erpnext/selling/report/quotation_trends/quotation_trends.py b/erpnext/selling/report/quotation_trends/quotation_trends.py index 5f96e07f541..92f9d17a9c7 100644 --- a/erpnext/selling/report/quotation_trends/quotation_trends.py +++ b/erpnext/selling/report/quotation_trends/quotation_trends.py @@ -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] diff --git a/erpnext/selling/report/sales_order_trends/sales_order_trends.py b/erpnext/selling/report/sales_order_trends/sales_order_trends.py index fdd63cd5a68..0827110ae5d 100644 --- a/erpnext/selling/report/sales_order_trends/sales_order_trends.py +++ b/erpnext/selling/report/sales_order_trends/sales_order_trends.py @@ -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]