Serial no fix
diff --git a/patches/1401/fix_serial_no_status_and_warehouse.py b/patches/1401/fix_serial_no_status_and_warehouse.py
index fe43c28..9e5579c 100644
--- a/patches/1401/fix_serial_no_status_and_warehouse.py
+++ b/patches/1401/fix_serial_no_status_and_warehouse.py
@@ -4,14 +4,16 @@
from __future__ import unicode_literals
import webnotes
+
def execute():
serial_nos = webnotes.conn.sql("""select name from `tabSerial No` where docstatus=0
and status in ('Available', 'Sales Returned') and ifnull(warehouse, '') = ''""")
for sr in serial_nos:
try:
- sr_bean = webnotes.bean("Serial No", sr[0])
- sr_bean.make_controller().via_stock_ledger = True
- sr_bean.save()
+ last_sle = webnotes.bean("Serial No", sr[0]).make_controller().get_last_sle()
+ if last_sle.actual_qty > 0:
+ webnotes.conn.set_value("Serial No", sr[0], "warehouse", last_sle.warehouse)
+
webnotes.conn.commit()
except:
pass
\ No newline at end of file
diff --git a/stock/doctype/serial_no/serial_no.py b/stock/doctype/serial_no/serial_no.py
index e6557b4..57b3b46 100644
--- a/stock/doctype/serial_no/serial_no.py
+++ b/stock/doctype/serial_no/serial_no.py
@@ -87,8 +87,6 @@
self.doc.status = "Sales Returned"
else:
self.doc.status = "Available"
- if not self.doc.warehouse:
- self.doc.warehouse = last_sle.warehouse
else:
if document_type == "Purchase Return":
self.doc.status = "Purchase Returned"