diff --git a/erpnext/stock/report/stock_ledger/stock_ledger.py b/erpnext/stock/report/stock_ledger/stock_ledger.py
index 23311bcda565..4e79c1bcf39d 100644
--- a/erpnext/stock/report/stock_ledger/stock_ledger.py
+++ b/erpnext/stock/report/stock_ledger/stock_ledger.py
@@ -20,18 +20,16 @@
def execute(filters=None):
is_reposting_item_valuation_in_progress()
if filters.get("include_uom") and filters.get("type") != "Default UOM":
- frappe.throw(str("Cannot select filters Include UOM and Select UOM together!"))
+ frappe.throw(
+ _(
+ f"Cannot select filters {frappe.bold ('Include UOM')} and {frappe.bold('Select UOM')} together!"
+ )
+ )
include_uom = filters.get("include_uom")
- if filters.get("type") == "Purchase UOM":
- type = "Purchase UOM"
- elif filters.get("type") == "Sales UOM":
- type = "Sales UOM"
- else:
- type = ""
columns = get_columns(filters)
items = get_items(filters)
sl_entries = get_stock_ledger_entries(filters, items)
- item_details = get_item_details(items, sl_entries, include_uom, type)
+ item_details = get_item_details(items, sl_entries, include_uom, filters)
opening_row = get_opening_balance(filters, columns, sl_entries)
precision = cint(frappe.db.get_single_value("System Settings", "float_precision"))
@@ -361,7 +359,7 @@ def get_items(filters):
return items
-def get_item_details(items, sl_entries, include_uom, type):
+def get_item_details(items, sl_entries, include_uom, filters):
item_details = {}
if not items:
items = list(set(d.item_code for d in sl_entries))
@@ -370,34 +368,26 @@ def get_item_details(items, sl_entries, include_uom, type):
return item_details
item = frappe.qb.DocType("Item")
+ ucd = frappe.qb.DocType("UOM Conversion Detail")
query = (
frappe.qb.from_(item)
.select(item.name, item.item_name, item.description, item.item_group, item.brand, item.stock_uom)
+ .select(ucd.conversion_factor)
.where(item.name.isin(items))
)
-
- ucd = frappe.qb.DocType("UOM Conversion Detail")
if include_uom:
- query = (
- query.left_join(ucd)
- .on((ucd.parent == item.name) & (ucd.uom == include_uom))
- .select(ucd.conversion_factor)
- )
- if type == "Sales UOM":
+ query = query.left_join(ucd).on((ucd.parent == item.name) & (ucd.uom == include_uom))
+ if filters.get("type") == "Sales UOM":
query = (
query.left_join(ucd)
.on((ucd.parent == item.name) & (ucd.uom == item.sales_uom))
- .select(ucd.conversion_factor)
- .as_("sales_uom_con")
.select(ucd.uom)
.as_("sales_uom")
)
- elif type == "Purchase UOM":
+ elif filters.get("type") == "Purchase UOM":
query = (
query.left_join(ucd)
.on((ucd.parent == item.name) & (ucd.uom == item.purchase_uom))
- .select(ucd.conversion_factor)
- .as_("purchase_uom_con")
.select(ucd.uom)
.as_("purchase_uom")
)
diff --git a/erpnext/stock/utils.py b/erpnext/stock/utils.py
index 163f057e5174..4293ac9a9163 100644
--- a/erpnext/stock/utils.py
+++ b/erpnext/stock/utils.py
@@ -462,7 +462,9 @@ def update_included_uom_in_report(
else:
new_value = flt(value) / conversion_factors[row_idx]
if type_conversion_factors:
- new_value = flt(value) / (type_conversion_factors[0][0] if type_conversion_factors[0][0] else 1)
+ new_value = flt(value) / (
+ type_conversion_factors[0][0] if type_conversion_factors[0][0] else 1
+ )
if not is_dict_obj:
row.insert(key + 1, new_value)
elif include_uom: