From faf51d91b656bfbe820b91ab332a4c81ed02ffcc Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Tue, 4 Apr 2017 11:35:22 +0530 Subject: [PATCH] [fix] stock qty issue in purchase trends report --- erpnext/controllers/trends.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/erpnext/controllers/trends.py b/erpnext/controllers/trends.py index c5db2239b3..23bc531cf0 100644 --- a/erpnext/controllers/trends.py +++ b/erpnext/controllers/trends.py @@ -140,16 +140,20 @@ def period_wise_columns_query(filters, trans): else: trans_date = 'transaction_date' + qty_field = "t2.stock_qty" + if trans == 'Purchase Invoice': + qty_field = "t2.qty" + if filters.get("period") != 'Yearly': for dt in bet_dates: get_period_wise_columns(dt, filters.get("period"), pwc) - query_details = get_period_wise_query(dt, trans_date, query_details) + query_details = get_period_wise_query(dt, trans_date, query_details, qty_field) else: pwc = [_(filters.get("fiscal_year")) + " ("+_("Qty") + "):Float:120", _(filters.get("fiscal_year")) + " ("+ _("Amt") + "):Currency:120"] - query_details = " SUM(t2.stock_qty), SUM(t2.base_net_amount)," + query_details = " SUM(%s), SUM(t2.base_net_amount),"%(qty_field) - query_details += 'SUM(t2.stock_qty), SUM(t2.base_net_amount)' + query_details += 'SUM(%s), SUM(t2.base_net_amount)'%(qty_field) return pwc, query_details def get_period_wise_columns(bet_dates, period, pwc): @@ -160,10 +164,10 @@ def get_period_wise_columns(bet_dates, period, pwc): pwc += [_(get_mon(bet_dates[0])) + "-" + _(get_mon(bet_dates[1])) + " (" + _("Qty") + "):Float:120", _(get_mon(bet_dates[0])) + "-" + _(get_mon(bet_dates[1])) + " (" + _("Amt") + "):Currency:120"] -def get_period_wise_query(bet_dates, trans_date, query_details): - query_details += """SUM(IF(t1.%(trans_date)s BETWEEN '%(sd)s' AND '%(ed)s', t2.stock_qty, NULL)), +def get_period_wise_query(bet_dates, trans_date, query_details, qty_field): + query_details += """SUM(IF(t1.%(trans_date)s BETWEEN '%(sd)s' AND '%(ed)s', %(qty_field)s, NULL)), SUM(IF(t1.%(trans_date)s BETWEEN '%(sd)s' AND '%(ed)s', t2.base_net_amount, NULL)), - """ % {"trans_date": trans_date, "sd": bet_dates[0],"ed": bet_dates[1]} + """ % {"trans_date": trans_date, "sd": bet_dates[0],"ed": bet_dates[1], "qty_field": qty_field} return query_details @frappe.whitelist(allow_guest=True)