Merge pull request #18859 from rohitwaghchaure/incorrect_valuation_rate_calculated_for_serial_no_develop
fix: incorrect valuation rate calculated because of string replacement
diff --git a/erpnext/stock/stock_ledger.py b/erpnext/stock/stock_ledger.py
index 920fc27..f7deac3 100644
--- a/erpnext/stock/stock_ledger.py
+++ b/erpnext/stock/stock_ledger.py
@@ -227,9 +227,9 @@
elif actual_qty < 0:
# In case of delivery/stock issue, get average purchase rate
# of serial nos of current entry
- stock_value_change = -1 * flt(frappe.db.sql("""select sum(purchase_rate)
- from `tabSerial No` where name in (%s)""" % (", ".join(["%s"]*len(serial_no))),
- tuple(serial_no))[0][0])
+ stock_value_change = -1 * flt(frappe.get_all("Serial No",
+ fields=["sum(purchase_rate)"],
+ filters = {'name': ('in', serial_no)}, as_list=1)[0][0])
new_stock_qty = self.qty_after_transaction + actual_qty