[fix] stock qty issue in purchase trends report
diff --git a/erpnext/controllers/trends.py b/erpnext/controllers/trends.py
index c5db223..23bc531 100644
--- a/erpnext/controllers/trends.py
+++ b/erpnext/controllers/trends.py
@@ -140,16 +140,20 @@
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 @@
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)