From 658f29915a2bf70ec722aa84b9cebcb8b7875da8 Mon Sep 17 00:00:00 2001 From: marination Date: Tue, 19 May 2020 13:58:13 +0530 Subject: [PATCH] fix: PR and DN trend report charts, group by fixes --- .../report/delivery_note_trends/delivery_note_trends.py | 9 +++++++-- .../purchase_receipt_trends/purchase_receipt_trends.py | 9 +++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/erpnext/stock/report/delivery_note_trends/delivery_note_trends.py b/erpnext/stock/report/delivery_note_trends/delivery_note_trends.py index d088b0020d..40a639bc09 100644 --- a/erpnext/stock/report/delivery_note_trends/delivery_note_trends.py +++ b/erpnext/stock/report/delivery_note_trends/delivery_note_trends.py @@ -12,17 +12,22 @@ def execute(filters=None): conditions = get_columns(filters, "Delivery Note") data = get_data(filters, conditions) - chart_data = get_chart_data(data) + chart_data = get_chart_data(data, filters) return conditions["columns"], data, None, chart_data -def get_chart_data(data): +def get_chart_data(data, filters): if not data: return [] labels, datapoints = [], [] + if filters.get("group_by"): + # consider only consolidated row + data = [row for row in data if row[0]] + if len(data) > 10: + # get top 10 if data too long data = sorted(data, key = lambda i: i[-1],reverse=True) data = data[:10] diff --git a/erpnext/stock/report/purchase_receipt_trends/purchase_receipt_trends.py b/erpnext/stock/report/purchase_receipt_trends/purchase_receipt_trends.py index 627c23b105..3b8d8d2dcd 100644 --- a/erpnext/stock/report/purchase_receipt_trends/purchase_receipt_trends.py +++ b/erpnext/stock/report/purchase_receipt_trends/purchase_receipt_trends.py @@ -12,17 +12,22 @@ def execute(filters=None): conditions = get_columns(filters, "Purchase Receipt") data = get_data(filters, conditions) - chart_data = get_chart_data(data) + chart_data = get_chart_data(data, filters) return conditions["columns"], data, None, chart_data -def get_chart_data(data): +def get_chart_data(data, filters): if not data: return [] labels, datapoints = [], [] + if filters.get("group_by"): + # consider only consolidated row + data = [row for row in data if row[0]] + if len(data) > 10: + # get top 10 if data too long data = sorted(data, key = lambda i: i[-1],reverse=True) data = data[:10]