From cffe577028ef63628c86bedab1c939ccb14f9707 Mon Sep 17 00:00:00 2001 From: Deepesh Garg <42651287+deepeshgarg007@users.noreply.github.com> Date: Thu, 5 Sep 2019 16:03:15 +0530 Subject: [PATCH] fix: Add UOM in anlytics report when viewing based on item (#18902) --- .../report/sales_analytics/sales_analytics.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/erpnext/selling/report/sales_analytics/sales_analytics.py b/erpnext/selling/report/sales_analytics/sales_analytics.py index 8a5e50a61e..72767f0689 100644 --- a/erpnext/selling/report/sales_analytics/sales_analytics.py +++ b/erpnext/selling/report/sales_analytics/sales_analytics.py @@ -40,6 +40,16 @@ class Analytics(object): "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({ @@ -129,7 +139,7 @@ class Analytics(object): 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 @@ -198,6 +208,10 @@ class Analytics(object): 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): @@ -232,6 +246,9 @@ class Analytics(object): 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)