Utility: reset serial no status and warehouse
diff --git a/erpnext/utilities/repost_stock.py b/erpnext/utilities/repost_stock.py
index e4028b6..1c6782a 100644
--- a/erpnext/utilities/repost_stock.py
+++ b/erpnext/utilities/repost_stock.py
@@ -190,3 +190,18 @@
"posting_date": posting_date,
"posting_time": posting_time
})
+
+def reset_serial_no_status_and_warehouse(serial_nos=[]):
+ if not serial_nos:
+ serial_nos = frappe.db.sql_list("""select name from `tabSerial No` where status != 'Not in Use'
+ and docstatus = 0""")
+ for serial_no in serial_nos:
+ try:
+ sr = frappe.get_doc("Serial No", serial_no)
+ sr.via_stock_ledger = True
+ sr.save()
+ except:
+ pass
+
+ frappe.db.sql("""update `tabSerial No` set warehouse='' where status in ('Delivered', 'Purchase Returned')""")
+
\ No newline at end of file