Skip to content

Commit

Permalink
fix: Add UOM in anlytics report when viewing based on item (#18901)
Browse files Browse the repository at this point in the history
  • Loading branch information
deepeshgarg007 authored and nabinhait committed Sep 5, 2019
1 parent ea2cdf8 commit 00f6fd8
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion erpnext/selling/report/sales_analytics/sales_analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@ def get_columns(self):
"fieldtype": "Data",
"width": 140
})

if self.filters.tree_type == "Item":
self.columns.append({
"label": _("UOM"),
"fieldname": 'stock_uom',
"fieldtype": "Link",
"options": "UOM",
"width": 100
})

for end_date in self.periodic_daterange:
period = self.get_period(end_date)
self.columns.append({
Expand Down Expand Up @@ -107,7 +117,7 @@ def get_sales_transactions_based_on_items(self):
value_field = 'qty'

self.entries = frappe.db.sql("""
select i.item_code as entity, i.item_name as entity_name, i.{value_field} as value_field, s.{date_field}
select i.item_code as entity, i.item_name as entity_name, i.stock_uom, i.{value_field} as value_field, s.{date_field}
from `tab{doctype} Item` i , `tab{doctype}` s
where s.name = i.parent and i.docstatus = 1 and s.company = %s
and s.{date_field} between %s and %s
Expand Down Expand Up @@ -176,6 +186,10 @@ def get_rows(self):
total += amount

row["total"] = total

if self.filters.tree_type == "Item":
row["stock_uom"] = period_data.get("stock_uom")

self.data.append(row)

def get_rows_by_group(self):
Expand Down Expand Up @@ -210,6 +224,9 @@ def get_periodic_data(self):
self.entity_periodic_data.setdefault(d.entity, frappe._dict()).setdefault(period, 0.0)
self.entity_periodic_data[d.entity][period] += flt(d.value_field)

if self.filters.tree_type == "Item":
self.entity_periodic_data[d.entity]['stock_uom'] = d.stock_uom

def get_period(self, posting_date):
if self.filters.range == 'Weekly':
period = "Week " + str(posting_date.isocalendar()[1]) + " " + str(posting_date.year)
Expand Down

0 comments on commit 00f6fd8

Please sign in to comment.