fix: Add UOM in anlytics report when viewing based on item (#18902)
diff --git a/erpnext/selling/report/sales_analytics/sales_analytics.py b/erpnext/selling/report/sales_analytics/sales_analytics.py
index 8a5e50a..72767f0 100644
--- a/erpnext/selling/report/sales_analytics/sales_analytics.py
+++ b/erpnext/selling/report/sales_analytics/sales_analytics.py
@@ -40,6 +40,16 @@
"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 @@
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 @@
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 @@
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)