diff --git a/erpnext/stock/stock_ledger.py b/erpnext/stock/stock_ledger.py index 30e0772b15c..0b2093fe765 100644 --- a/erpnext/stock/stock_ledger.py +++ b/erpnext/stock/stock_ledger.py @@ -10,7 +10,7 @@ import frappe from frappe import _, bold, scrub from frappe.model.meta import get_field_precision from frappe.query_builder import Order -from frappe.query_builder.functions import Lower, Sum +from frappe.query_builder.functions import Lower, NullIf, Sum from frappe.utils import ( cint, flt, @@ -1975,7 +1975,7 @@ def get_valuation_rate( table = frappe.qb.DocType("Stock Ledger Entry") query = ( frappe.qb.from_(table) - .select(Sum(table.stock_value_difference) / Sum(table.actual_qty)) + .select(Sum(table.stock_value_difference) / NullIf(Sum(table.actual_qty), 0)) .where( (table.item_code == item_code) & (table.warehouse == warehouse)